• 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

Help me with this Exception in GUI

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, i just got this and i don't know what's wrong!
--------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------------
Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at GUI5.<init>(GUI5.java:12)
at GUI5.main(GUI5.java:17)
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

I have moved you to a more appropriate location, and edited your post to remove the red text, which some people can't can't read, and added code tags, which usually make the code look nso much better. Unfortunately in this instance, they simply show how very badly that code is formatted
The message about the exception is clear. But null pointer exceptions don't occur where the error is. The real error is in line 9. Have a look.

Don't extend JFrame. Don't make those components fields of the class. Make them local variables. Don't call setVisible() from the constructor. Call it in a method. Don't give a JPanel FlowLayout, because it has that layout as a default. I don't like flow layout myself; I don't think it is any good.
 
Saloon Keeper
Posts: 7585
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is in line 9.
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It would also be more obvious which bit exactly was causing the issue if you didn't squish all your lines together like that.
reply
    Bookmark Topic Watch Topic
  • New Topic