• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Null Pointer Execption error when running application

 
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where is the stack trace?
 
Varnam Aayiram
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi..

Thanks for the reply, the stack trace is as follows:
 
Bear Bibeault
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure what you mean by that. The verb "call" is completely ambiguous in this context.
 
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic