Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Getting NullPointerException

Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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(

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??

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.
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".
We don't have time to be charming! Quick, read this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic