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



I spent years trying to get people to code COBOL to some kind of standard, so I'm having a half-life off.
To be honest, I find the upper/lower case convention really annoying. I don't think it improves readability - I'd rather use under_scores.
Bob.


On 31 Jan 2006, at 15:35, String Larson wrote:


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





_______________________________________________ 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>)
 >Re: yet another irritating newbie question ..... (From: String Larson <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.