Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java lang Null PointerException

 
bobby reddy
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,
i have created a jsp. when i click save button, the data is being stored in the corresponding tables at the back end.When i try to see the data and again click save button later, it displays me java lang Null Pointer Exception. i have written output statements also but could not track this exception. Could any one tell me how to avoid this exception?

Thanks,
bobby
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64827
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't de-reference nulls.

Sorry if that seems flip, but there's really not much else to say with the scant information you've given. The stack trace should tell you the exact line where the NPE is occurring. From there you should be able to backtrack to find out why you have a null reference that you did not expect
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what you mean by "you could not track this exception". Wrap the statement in a try/catch block and post the stack trace. (Of course, you shouldn't be using Java code in a JSP to begin with, but that's a different issue.) In addition to the stack trace, also post the code that's causing it. Otherwise we'll have no clue on how to advise you.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start by looking at your server's logs.

Often you will get the exact line number in the JSP where the NullPointerException was thrown. Depending on the server, you might, instead get the line number in the generated servlet code.

Once you find the line number, look in that line for a method being called on an object. If there is only one method call on that line, you've found the object that is null. From there it should be easy to find the bug.

If there is any part of this that you don't understand, ask for clarification.
-Ben
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic