aspose file tools*
The moose likes Beginning Java and the fly likes error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "error" Watch "error" New topic
Author

error

Victoria Preston
Ranch Hand

Joined: Feb 03, 2006
Posts: 106
I am trying to run my program....but everytime I do I get an error message that says
Exception in thread "main" java.lang.NullPointerException

what does this mean
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

It means that something on the left side of a dot (.) is 'null' -- either a variable is set to null, or a function is returning null. The stack trace (the error message) tells you what line the error happened at: the top line will say something like

at MyClass.main (MyClass.java:21)

that means the error happened on line 21 of MyClass.java . Look at any dots on that line -- that's where the problem is. We'd be happy to look at the code for you, if you want -- paste it into a reply in this thread. Put [ CODE ] [/ CODE ] tags around the code to preserve formatting in your post (take out the spaces in the tags.)


[Jess in Action][AskingGoodQuestions]
Victoria Preston
Ranch Hand

Joined: Feb 03, 2006
Posts: 106


there is the code i'm trying to test and here is the code in my test



hope you can help
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

You didn't show the stack trace or tell me what line it says the error is on, so I have to guess!

The method "contains" references a member variable named "list" (different from the local variable in main of the same name). The member variable "list" is an array. My first guess is that either that member variable is "null" (does anything ever assign a value to it?) or one of the elements of that array is "null" (remember that constructing an array makes an array of null references; there are no objects in the array until they are created.

But it looks like "contains" is as method in some kind of a collection class; it's likely that there's a separate variable that tells how many elements are really in the array; this number is smaller than or equal to the size of the array. The member variable that hold this count should be used as the upper limit of the for loop, not the array length.

Do any of these hints help?
Victoria Preston
Ranch Hand

Joined: Feb 03, 2006
Posts: 106
so instead of .length it needs to be .size


and yes they help bunches thanks
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

Originally posted by Victoria Preston:
so instead of .length it needs to be .size


Well, no, not exactly. I'm imagining that EmployeeClass looks like



So I'm talking about using "size" in place of "list.length" -- but this is only if my guess is right that there is a member like "size". Maybe you should show us the whole "EmployeeList" class (unless you figure this out by yourself now.)
Victoria Preston
Ranch Hand

Joined: Feb 03, 2006
Posts: 106
okay sorry about the hold up had to go to the store. Here is the entire EmployeeList any feedback would help.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: error