• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Getting an error on the line with the while loop that uses the iterator

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do not understand as to why am I getting this error on this program because the example program runs fine on the internet.
I get this error on the while loop line:

Exception in thread "main" java.lang.NullPointerException
at MalJavaChapter3.TestCollection1.main(TestCollection1.java:16)


On the example with linked lists (class TestCollections7) the same while loop does not give an error.
It works fne.

Please help
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That code should work. Have you tried cleaning and rebuilding your project? How do you run the application?
 
Martin Ndhlovu
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am usiing the eclipse IDE, there is something definetely wrong within. Some example programs are running fine and some are not.
Maybe it is too old or something, I do not know.  Would you suggest a better IDE to use?
 
Bartender
Posts: 732
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
is the code you posted actually the code that you executed? The posted code cannot encounter a NullPointerException at line 16.
 
Martin Ndhlovu
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have this example program :


It runs 100% okay.
It is exactly the same as the one that I get a nullExceptionpointer with.
Now I do not know why does the  other one give me an error.
That is why I think there is something wrong with my eclipse IDE
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The two programs are different; the error message shows that. The Exception occurs in line 16, which consists only of a } in the code you posted, and the class name has MalJavaChapter3 in; that means there is a package name which you have missed out when you quoted the code. You must always post the real code with all the details, otherwise you will get the wrong answers.
The two classes you posted can be executed without any Exceptions. But it is possible that what you executed on Eclipse was slightly different. You have not shown any evidence that there is anything wrong with your Eclipse installation.
 
Ranch Hand
Posts: 4716
9
Scala Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Personally, I don't and won't use any ide. I use notepad++ and compile from the command line.
 
reply
    Bookmark Topic Watch Topic
  • New Topic