This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Null Pointer Execption error when running application

 
Varnam Aayiram
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where is the stack trace?
 
Varnam Aayiram
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..

Thanks for the reply, the stack trace is as follows:
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64700
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what you mean by that. The verb "call" is completely ambiguous in this context.
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic