File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Null Pointer Execption error when running application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Null Pointer Execption error when running application" Watch "Null Pointer Execption error when running application" New topic
Author

Null Pointer Execption error when running application

Varnam Aayiram
Ranch Hand

Joined: Dec 23, 2008
Posts: 88
Hi folks...

I am trying to display content from a table in a database. I am using datasource to do this. When I run the application I
am getting the following error:

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: java.lang.NullPointerException
root cause

java.lang.NullPointerException

-----------------------------------------------------------------------------------

The 3 files involed are as follows:

us_states.jsp:


JDBCSelectServlet.java:



UsStateBean.java:


I am not sure what is wrong. Can anyone point out the problem to me? Thanks.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

Where is the stack trace?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Varnam Aayiram
Ranch Hand

Joined: Dec 23, 2008
Posts: 88
Hi..

Thanks for the reply, the stack trace is as follows:
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

OK, so at least we now know that it's coming from the JSP.

Most likely reason is that either of stateList or state ends up as null.

By the way, why are you still using outdated scriptlets and scriptlet expressions? You've already separated the logic form the JSP, using the JSTL and EL should be a snap.
Varnam Aayiram
Ranch Hand

Joined: Dec 23, 2008
Posts: 88
Bear Bibeault wrote:OK, so at least we now know that it's coming from the JSP.

Most likely reason is that either of stateList or state ends up as null.

By the way, why are you still using outdated scriptlets and scriptlet expressions? You've already separated the logic form the JSP, using the JSTL and EL should be a snap.


Hi there Bear Bibeault ,

Appreciate the reply. I will look into the possibility that you have highlighted. I am also wondering if the setting up of the datasource in my glassfish server could also be a possible cause, but I am able to do a ping sucessfully after setting up the datasource...

Actually these codes are something that I got from a book. I am trying them out on my machine to better understand them, so that I can implement something similar on an application I am developing. Yes, I have heard of JSTL and EL and how they can make life easier. Once I settle this 'nullpointer' issue, I will replace the scriplets with JSTL/EL. Thanks once again.

Varnam Aayiram
Ranch Hand

Joined: Dec 23, 2008
Posts: 88
Hi...

I am just curious, the file us_states.jsp does not explictly 'call' any particular servlet, unlike a form submission where a servlet is mentioned explicitly. So how does the server know which servlet to call/invoke?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

I'm not sure what you mean by that. The verb "call" is completely ambiguous in this context.
Mark E Hansen
Ranch Hand

Joined: Apr 01, 2009
Posts: 650
Varnam Aayiram wrote:Hi...

I am just curious, the file us_states.jsp does not explictly 'call' any particular servlet, unlike a form submission where a servlet is mentioned explicitly. So how does the server know which servlet to call/invoke?

It looks like your JSP page is going to display a list of states, but not otherwise do anything at all. Is this what was intended?
Did you want the user to select a state, then click on a Submit button or something? That appears to not be there.

Shinelin Samuel
Ranch Hand

Joined: Mar 01, 2010
Posts: 55
Hi,

Like you mentioned you are setting up the environment for this project, double check if you the table us_states has records, loaded in it.

Probably that could the reason for your issue.

Regards,
Shinelin
Shailendra Mishra
Greenhorn

Joined: Mar 05, 2010
Posts: 4
Hi,

WHILE YOU ARE PUTTING THE VALUE IN ARRAY LIST EITHER resultset is nothing return or the way you Are ptting need to watch it again.

Jinglong Wang
Greenhorn

Joined: Mar 05, 2010
Posts: 12
hi,
i need know how do you run this.
direct run the jsp or request a servlet?

if you direct run the jsp,the nullpoint is right.
the nullpointException throw out in line 25.
because the stateList is null.
Varnam Aayiram
Ranch Hand

Joined: Dec 23, 2008
Posts: 88
Hi Guys..

Thanks for the replies, I appreciate it. Yes as some of you had pointed out, the mistake was in running from the jsp direct. I have rectified the mistake. Thanks everyone.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Null Pointer Execption error when running application