File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes null pointer exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "null pointer exception" Watch "null pointer exception" New topic
Author

null pointer exception

terry oliver
Greenhorn

Joined: Jan 04, 2008
Posts: 22
help can anyone help it does compile and thows the exception at runtime.

private void okButton_actionPerformed(ActionEvent e)
{
System.out.println("\nokButton_actionPerformed(ActionEvent e) called.");

nt.setSteel(Double.parseDouble(newSteelSize.getText()));
System.out.println("adjused steel = "+nt.getSteel());
this.dispose();
}
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

A NullPointerException happens when something directly to the left of a "." or "[" operator is null at the time the line of code executes. Here, that could be the variables "nt" or "newSteelSize". Carefully check the code elsewhere in your application that's supposed to set those to some value.

One beginner mistake that's very likely to be the cause of this: make sure that in your class's constructor, you're not accidentally declaring local variables with the same names as these members. You should be writing

nt = ...

not

Whatever nt = ...

The stack trace should tell you exactly which line the error occurred on; it's probably that "setSteel" line, since both variables are used there.


[Jess in Action][AskingGoodQuestions]
Bruno Giminiani
Greenhorn

Joined: May 15, 2008
Posts: 1
Hi Terry, there is a list of top ten error by java programmers.
"Null Pointer" is the FIRST. See the link: http://www.javacoffeebreak.com/articles/toptenerrors.html

Greetings,
Bruno Giminiani
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: null pointer exception