ok,i've made a small program..for educational porpuses only... i have two Packages..the first named "impl":
The second package is named "UserData":
The main Program(class with the main method looks like that) :
when im trying to compile that im getting the following error: "Hit uncaught exception java.lang.NullPointerException"
any idea? [ November 27, 2004: Message edited by: Joe nothing ]
Joined: Aug 08, 2003
UserLog uL1 = new UserLog;
creates an array of 10 references to UserLogs, however, it doesn't create UserLog objects for them to refer to, they all refer to null.
so, the line
attempts to access the setFirstName method of null, which it doesn't have, of course, and you get the NullPointerException.
Joined: Oct 20, 2004
UserLog uL1 = new UserLog; //creates 11 reference variables of UserLog type
--->uL1 = new UserLog(); //create the object that uL1 will refer to uL1.SetFirstName("nnn");
to initialize each one, use a simple for loop.
Joined: Nov 20, 2004
ohh....now i see. many thanks guys!
Joined: Aug 07, 2003
And here are a few usage and style pointers.Make sure you use String.equals(String) when comparing Strings and other objects. The == and != operators test the references for equality -- not the objects to which they refer. Sometimes you do want to test for reference equality, but not usually. The above should beThe first part before the && is to make sure you don't get a NullPointerException if fname is null and the second part uses trim() in case fname is " " (a space).
Java style typically saves TitleCasing for interface and class names. Packages (impl) are usually all lowercase and methods (setFirstName) leave their first character in lowercase. Constants (you didn't use any, but e.g. EMPTY_NAME = "") use all caps with underscores separating words.
Following the standards that are almost universal will make working on a team and reading from books easier. Feel free to deviate when you have a good reason.
Joined: Aug 20, 2001
Welcome to JavaRanch! UNfortunately, your display name does not meet the JavaRanch Naming Policy. (If you don't want to use your own name, at least pick a name that looks real.) You can change it here.
Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
author and iconoclast