Win a copy of Learning Regular Expressions this week in the General Computing forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

null pointer exception  RSS feed

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
}
 
author and iconoclast
Sheriff
Posts: 24220
40
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!