• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Null pointer error within my Custom Tag

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 67746
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
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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
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
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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome.

And we leave threads open, so others may learn from it in the future.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic