• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

error

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
We don't have time for this. We've gotta save the moon! Or check this out:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic