On Jan 29, 2006, at 7:58 AM, Bob Irving wrote:
Dear list,
Sorry to post non-Mac related java stuff, but you can only
subscribe to so many lists.
can anyone bite my head off and explain why the following minute
piece of code generates the following error:
code-----------------------------------------------------------------
-----------------------
import org.dom4j.*;
import org.dom4j.Document;
import org.dom4j.util.UserDataElement;
import org.dom4j.DocumentHelper;
import java.io.*;
public class PriceElement extends UserDataElement
{
public String currency, price, elementName;
public PriceElement (String currency, String price, String
elementName)
{
UserDataElement PriceElement = new UserDataElement(elementName);
Element money = PriceElement.addElement("Money");
money.addAttribute( "currency", currency);
money.addText(price);
return PriceElement;
}
}
error
---------------------------------------------------------------------
---------------------
[javac] /Users/bobirvin/Sites/SupplierConnect/src/ejb/com/
kenisys/supplierconnect/handler/PriceElement.java:14: cannot
resolve symbol
[javac] symbol : constructor UserDataElement ()
[javac] location: class org.dom4j.util.UserDataElement
[javac] {
[javac] ^
<---- pedantic on ------->
Since others have solved the problem, I want to comment on the code
itself.
Please read:
http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html
A few points:
avoid using ' * ' in imports:
you have
import org.dom4j.*;
and then
import org.com4j.Document;
etc.
Avoid:
public String currency, price, elementName;
A couple of things here:
1) currency, price, and elementName should be private or protected
and not public.
2) currency, price, elementName should be declared on separate lines:
eg.
private String currency;
private String price;
private String elementName;
All variables should begin with lower case.
e.g.
UserDataElement PriceElement = ...
should be:
UserDataElement priceElement = ...
Finally, I would highly recommend using a tool such as Eclipse or
IntelliJ as you environment.
These tools will help you write better code.
Also, you can have it 'build automatically'. The compiler runs in
the background as you type.
This gets you out of the code, compile, fix compile errors,
compile, etc. cycle.
-string