aspose file tools*
The moose likes JSP and the fly likes NullPointerException in SimpleTag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "NullPointerException in SimpleTag" Watch "NullPointerException in SimpleTag" New topic
Author

NullPointerException in SimpleTag

Arun Somasundaram
Ranch Hand

Joined: Jul 25, 2006
Posts: 63
Hi all,

I use tomact 5.5.17 container.
I am getting a NullPointerException when using a simple tag

Here is my code for jsp(simpletag.jsp):-



Here is the code for the class that implements SimpleTagSupport class



Here is the TLD:-
This file is located at employee/WEB-INF/tlds folder.
where employee is the webapp name


When i execute the simpletag.jsp

http://localhost:8080/employee/simpletag.jsp?id=2

I get the follwing error:-



Can anyone give me a solution to get out of this problem.
[ September 15, 2006: Message edited by: Arun Somasundaram ]

Arun.V.Somasundaram
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Javaranch tip:

If you are going to post more than a line or two of your code, wrap that
code in a set of UBB Code tags.
Doing so will help to preserve your code's indenting, making it easier to read.
If it is easier to read, more people will actaully read it and you will
stand a better chance of getting help with your question.
See UseCodeTags for more
help with UBB code tags.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Arun Somasundaram
Ranch Hand

Joined: Jul 25, 2006
Posts: 63
Ben Souther,I have already added my code with in the tags,So what is the reason for asking me to add the code between the code tags.
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

java.lang.NullPointerExceptioncom.Image.doTag(Image.java:66)


So what's in line 66?

A quick look at your code revealed this



Shouldnt the executeQuery() method which returns a ResultSet be assigned to the 'rs' variable



ram.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I can see a few issues with this code.

1.) Why are you escaping the quotes in the getProperty method in your JSP?


2.) Your never checking to see if the "id" property is null before trying
to use it in your query.

3.) You're not testing rs.next() to see if it's actually returning a row.
Should be:

or if you expect multiple rows:



4.) Java exceptions will be more help to you if you print the entire stack trace:



Before writing to forums or lists to help with debugging a
NullPointerException, you should test all of your variables with simple
System.out.println(varName) statements to see which one is null.
Also, that stacktrace has line numbers for the the offending code.

Some of the lines are in your tag but some are in the generated servlet
code (which in Tomcat lives under the {tomcat install}/work directory.
These line numbers should help narrow down the search for you.



Also...

Once you get past this NullPointerException, you're probably going to run in to an IllegalStateException because you're trying to mix binary and texual output in the same response.
See: http://faq.javaranch.com/view?IllegalStateException

Custom tag or not, it is never a good idea to try to stream binary data from a JSP. This should be done from a servlet.
[ September 15, 2006: Message edited by: Ben Souther ]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Arun Somasundaram:
Ben Souther,I have already added my code with in the tags,So what is the reason for asking me to add the code between the code tags.


One reason for the code tags is the preservation of your code's indenting.
Since your code has no indenting, my first assumption was that there were no
code tags.
Had I looked closer, I would have seen that you did actually use them.

Do you really write your code without indenting?
[ September 15, 2006: Message edited by: Ben Souther ]
Arun Somasundaram
Ranch Hand

Joined: Jul 25, 2006
Posts: 63
I forgot to assign the ResultSet to its variable while posting.
But the code is right.I have corrected it in the posting.
Arun Somasundaram
Ranch Hand

Joined: Jul 25, 2006
Posts: 63
Ben I have checked the id , and the rs these are not null.But I can't able to find where the actual mistake lies.

Here is the stack trace from my logs directory.
Arun Somasundaram
Ranch Hand

Joined: Jul 25, 2006
Posts: 63
Ben I have checked the id , and the rs these are not null.But I can't able to find where the actual mistake lies.

Here is the stack trace from my logs directory.

Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

at org.apache.jsp.tag2_jsp._jspService(tag2_jsp.java:63)

Hint: Go back and read all of my earlier response if you're not sure what this means.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NullPointerException in SimpleTag