Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: yet another irritating newbie question .....



Bob Irving wrote:

	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:

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;
}

     [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]         ^

Others have commented on the general structure, and given good advice, but I haven't seen any comments specifically answering the question asked, which is why that particular error message was issued.

Since the constructor as written does not directly specify a superclass
constructor to be invoked, Java assumes a constructor with no parameters
(AKA the default constructor). If class UserDataElement has no default
constructor, this is the message that will be issued. The "cannot resolve
symbol" message means it cannot find the symbol in question. The symbol
it is referring to is "constructor UserDataElement ()" (note the empty
parenthesis, denoting no parameters, to disambiguate the symbol from any
other constructors the class may define). Since it lists the constructor
as the symbol in question, you can safely assume it is finding the class,
and your classpath is fine. I suspect that if you look at the JavaDoc for
UserDataElement you will find that it does not have a default constructor.
If the default constructor were private or package private, I think you'd
get a different message.


In other words, what you wrote was equivalent to:

public PriceElement (String currency, String price, String elementName)
{
super(); // specify the superclass default constructor
UserDataElement PriceElement = ...


Which will only work if UserDataElement has a default constructor:

    public UserDataElement() {
        ...

(it could also be declared protected instead of public).
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.