Hey all
Trying to handle a nullpointerexception error message that I get from
Tomcat.
<form action="mockup2.jsp" method="POST">
<input type="checkbox" name="shows" value="Ally McBeal">Ally McBeal
<input type="checkbox" name="shows" value="Buffy The
Vampire Slayer">Buffy The Vampire Slayer <br>
<input type="submit" name="submit" value="Select">
</form>
<%
String[] Shows;
Shows = request.getParameterValues("shows");
if (Shows[0] == null)
{
Shows[0]="" ;
} //I'm guessing this is faulty
//if (Shows[0].equals(null))
{
Shows[0]="1";
} //This didn't work either
out.println("<ul>");
for(int counter = 0; counter < Shows.length; counter++)
{
out.println("<li>" + Shows[counter]);
}
out.println("</ul>");
%>
I've been reading through the Java docs about arrays and such. But I
can't really wrap my head around how to error handle them and i'm
guessing that this is why my code doesn't work.
Here's the stack trace:
Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException at
org.apache.jsp.mockups.mockup2_jsp._jspService(org.apache.jsp.mockups.mockup2_jsp:85)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)
at
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
at
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
Mangiucugna - 14 Nov 2005 10:32 GMT
Try to test if show == null and not show[0]
deepstar@gmail.com - 14 Nov 2005 10:37 GMT
Still get the nullpointerexception, this works fine if I divide it on
two pages, but since I'm trying to do it on a single jsp page whenever
I load it "Shows" is null and therefore get the exception.
/going nuts over this :p
Mangiucugna - 14 Nov 2005 10:33 GMT
Try to test if show == null and not show[0]
Andrew Thompson - 14 Nov 2005 11:15 GMT
> String[] Shows;
...
> if (Shows[0] == null)
> {
> Shows[0]="" ;
> } //I'm guessing this is faulty
Good guess. But trying to debug this in a JSP, with the
limited knowledge of Java you seem to possess, is rather
pointless.
I suggest you work out how to use arrays from command
line applications instead.
<http://www.physci.org/codes/javafaq.jsp#appfirst>
Note that you will find more people willing to help with
such problems on c.l.j.help.
<http://www.physci.org/codes/javafaq.jsp#cljh>
HalcyonWild - 14 Nov 2005 14:35 GMT
> Hey all
>
> Trying to handle a nullpointerexception error message that I get from
> Tomcat.
[ something i deleted ]
There is no much use posting the exception trace of a jsp. It does give
an idea, but not fairly enough, the line numbers are all different from
the ones in JSP.
Now, look into the work/Catalina and lower subdirectories, and you
might find the generated servlet. use that servlet with the stacktrace.