Forums Register Login
null pointer exception
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.");

System.out.println("adjused steel = "+nt.getSteel());
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 = ...


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.
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

Bruno Giminiani
I'm so happy! And I wish to make this tiny ad happy too:
Rocket Oven Kickstarter - from the trailboss

This thread has been viewed 587 times.

All times above are in ranch (not your local) time.
The current ranch time is
Jul 15, 2018 23:05:40.