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 .....




On Jan 29, 2006, at 5: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:

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

This is a weird looking constructor. 

1) It is attempting to return a value, constructors don't return anything then just initialize the instance.
2) It isn't calling a construct for your super class before anything else in it (likely could call super(elementName)).
3) It is constructing a instance of UserDataElement when in fact PriceElement extends UserDataElement, so I think you are meaning to construct yourself instead.
4) You are using an instance variable that is the same name are your class (not even sure that will compile).
5) Your constructor takes 3 parameters that appear to align with 3 instance vars you have yet it doesn't assign anything to them (constructor isn't likely doing what you want).

I believe (2) is the source of the error you are getting but I bet you will get others once you fix that one.

I think you want (not looking at the java docs for UserDataElement...

public PriceElement (String currency, String price, String elementName)
{
super(elementName);
Element money = addElement("Money");
money.addAttribute( "currency", currency);
money.addText(price);
}

-Shawn
 _______________________________________________
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

References: 
 >yet another irritating newbie question ..... (From: Bob Irving <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.