Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting NullPointerException  RSS feed

 
pandu chinnu
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have been working with eclipse from the last week. It was all working fine.I was doing small example programs.Yesterday when I ran a program I got this NullPointerException.I tried to see if I had done any mistake in the coding...but it was all fine, moreover all my old programs which were working fine are also showing the same error "Exception in thread "main" java.lang.NullPointerException"
at Javax.swing.JMenu.add(JMenu.java.548)


when I click on the above, it shows Source Not Found - The jar file rt.jar has no source attachment. It also says you can attach the source by clicking attach source below : An Attach Source button.

Can anybody clarify the exact steps to rectify this problem??


Thanks
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is It giving any stack trace of this exception.If yes , then try to find out the faulty line of code from your program.
That is the cause of NullPointerException from JMenu.
 
Vanessa Astle
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A NullPointerException occurs when a variable has not been initialized. Say I created a Cat object (I'm just making up an object) reference variable, and didn't assign it a value, then tried to use that reference variable:

Cat snowball; //This is bad, I did not initialize cat.
CatFood tuna = new CatFood(); //This is good, I initialized CatFood.
snowball.feed(tuna); //When I call the method feed on my cat variable, the computer doesn't actually have a cat to feed.

So you must make sure that you initialize ALL of your variables, even if it is only to something useless, like "null".
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!