• 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 NullPointerException

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
I don't always make ads but when I do they're tiny
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic