Jump to content

ERROR: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
PFworth

PFworth

    Newbie

  • Members
  • Pip
  • 1 posts
I've been making a NetBeans Java version of Blackjack, and yesterday I came upon an error that has left my program error-ing out as soon as it launches. I'm new to Java, but I am very experienced with VB. The error reads,

Quote

run:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(ImageIcon.java:167)
at Main.initComponents(Main.java:118)
at Main.<init>(Main.java:51)
at Main$5.run(Main.java:661)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
BUILD SUCCESSFUL (total time: 2 seconds)

I really have no clue where to begin in getting my program to run. I'd really like to keep my program, rather than write it all over again! :cursing:

My screen is thrown off entirely as well, but that's less of a concern.

Thank you in advance!

#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
In your main class you created a method: initComponents(), in there you cause a nullpointerException, meaning that you use an object that isn't created yet.
JButton button;
button.text="click me" ; <<<------- nullpointerexception
this should be:
JButton button = new JButton();
button.text="click me";