File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes java lang Null PointerException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "java lang Null PointerException" Watch "java lang Null PointerException" New topic

java lang Null PointerException

bobby reddy

Joined: Nov 05, 2007
Posts: 27
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?

Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63548

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

[Asking smart questions] [About Bear] [Books by Bear]
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42959
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

Joined: Dec 11, 2004
Posts: 13410

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.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: java lang Null PointerException
It's not a secret anymore!