Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with GUI  RSS feed

 
Lee Guarino
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone

whenever i run my application and click on the button named "addPipe" it throws the following exception.

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:991)
at java.lang.Double.valueOf(Double.java:475)
at pipeapplication.GUI.actionPerformed(GUI.java:194)
at java.awt.Button.processActionEvent(Button.java:392)
at java.awt.Button.processEvent(Button.java:360)
at java.awt.Component.dispatchEventImpl(Component.java:4410)
at java.awt.Component.dispatchEvent(Component.java:4240)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:599)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)

 
Steffen Reinhard
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lee,

your Class GUI extends java.awt.Frame but you initialize all of your instance variables in an init() method, which would work in an Applet but isn't called automatically by the Java VM.

In an application, initialization of objects and primitives takes place in a constructor (such as public GUI(){...}). As your class doen't declare any constructors at all, the compiler decides to use the default constructor (which, in your case, happens to be the no-argument contructor of java.awt.Frame class).

Consider renaming the init() method to GUI() (to provide a contructor for the initialization of your variables) and give it another try ...

Cheers,


Steffen

[ December 24, 2006: Message edited by: Steffen Reinhard ]
[ December 24, 2006: Message edited by: Steffen Reinhard ]
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


when you click addPipe this is the sequence
stringIn set to null
if(e.getSource()==lengthTF) //false - addPipe was clicked, so the if does not execute
you have no {} to indicate the if block, so only the first line (ending ;) is bypassed
actionPerformed moves onto the next line
lengthIn = Double.parseDouble((String) stringIn);
but stringIn is null (Object stringIn = null ;)

[EDIT]
disable smileys
[ December 24, 2006: Message edited by: Michael Dunn ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!