Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

error

 
Victoria Preston
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
Victoria Preston
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so instead of .length it needs to be .size


and yes they help bunches thanks
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay sorry about the hold up had to go to the store. Here is the entire EmployeeList any feedback would help.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic