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