• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Martin Ndhlovu
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • 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
 
Stephan van Hulst
Saloon Keeper
Posts: 7991
143
  • Mark post as helpful
  • send pies
  • 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
  • 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?
 
Fred Kleinschmidt
Bartender
Posts: 571
9
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • 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.
 
Randall Twede
Ranch Hand
Posts: 4696
8
Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Personally, I don't and won't use any ide. I use notepad++ and compile from the command line.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!