Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Null pointer error within my Custom Tag  RSS feed

 
John Ross
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my customTag

Here is my index.jsp


my servlet -> i only included the parts that are needed.

Here is the tomcat error:


org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 33

30:
31:
32: <%@ taglib uri="/WEB-INF/tlds/runners.tld" prefix="jr" %>
33: <jr:displayRunner>
34: <tr valign="top">
35:
36:


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:568)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:470)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause

java.lang.NullPointerException
tags.DisplayTag.doStartTag(DisplayTag.java:28)
org.apache.jsp.index_jsp._jspService(index_jsp.java:104)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:390)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)

I believe the issue is related to my object within the displayTags.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

The exception specifies where it occurs - line 28 of class DisplayTag, inside method doStartTag. My guess it's this line:
That would mean that the attribute isn't set yet. Are you absolutely certain that the servlet has been executed before the JSP page? Are you also certain that you get no SQL exception, and you get at least one result? Because you are setting the same list for each record. You should instead just add to myRunners inside the while loop, and then set the attribute after it. That way the attribute will be set even if there are no results. Only if there's an SQL exception will the attribute not be set.
 
John Ross
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob-

It is working when I load the servlet first.
Should I change the web.xml to load the servlet?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65828
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP 2 was introduced 10 years ago. Why are you still using classic tag handling and using scriptlets in your JSP? :confused:
 
John Ross
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:JSP 2 was introduced 10 years ago. Why are you still using classic tag handling and using scriptlets in your JSP? :confused:


just testing some code, I will change it later.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65828
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kind of odd. Why not just do it right the first time? Sort of like "Why are you using vacuum tubes?" "I'll change it later."
 
John Ross
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob-

Thanks for your help. You hit the nail on the head. A simple redirector added to my servlet and a change to the web xml welcome file did it.

I don't know if I should delete this thread or just close it. But, I am good!
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.

And we leave threads open, so others may learn from it in the future.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!