Reputation: 51
I'm trying to make a program in NetBeans... It's supposed to be a Salad menu, everything is working fine unless I don't select any value... The error is this:
type Exception report
messageInternal Server Error
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 note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 4.1 logs.
Here's my JSP code:
<%
String prueba [] = request.getParameterValues("ingredientes");
out.println("<h1>RESULTADO DE TU ENSALADA!!</h1>");
out.println("<br><br><b>Tu ensalada tiene:</b><br>");
for (int o = 0; o < prueba.length; o++){
out.println(prueba [o]+"<br>");
String prueba2 [] = request.getParameterValues("adicionales");
out.println("<br><br><b> Adicional tiene:</b><br>");
for (int o = 0; o < prueba2.length; o++){
out.println(prueba2 [o]+"<br>");
String prueba3 [] = request.getParameterValues("aderezos");
out.println("<br><br><b> Con el aderezo:<br></b>");
for (int o = 0; o < prueba3.length; o++){
out.println(prueba3 [o]+"<br>");
%>
I know I'm missing some "}" but deleted them to keep the Code format. Already tried using "catch" but doesn't seem to work or maybe did it wrong. Any suggestions?
EDIT:
OK guys, so I just found a solution to my problem, I don't know why I didn't think of this earlier. Thanks for your quick answers.
This was my solution:
if (request.getParameterValues("ingredientes") != null){
String prueba [] = request.getParameterValues("ingredientes");
out.println("<h1>RESULTADO DE TU ENSALADA!!</h1>");
out.println("<br><br><b>Tu ensalada tiene:</b><br>");
for (int o = 0; o < prueba.length; o++){
out.println(prueba [o]+"<br>"); }
}else{
out.println("Selecciona UNO O MAS Ingrediente Porfavor!");
}
I just added this condition:
if (request.getParameterValues("ingredientes") != null)
Upvotes: 0
Views: 844
Reputation: 6711
At a guess I'd say that one of these is returning null.
String prueba [] = request.getParameterValues("ingredientes");
String prueba2 [] = request.getParameterValues("adicionales");
String prueba3 [] = request.getParameterValues("aderezos");
Then if you try to call
prueba.length
, and prueba is null
, you will get a NullPointerException
Upvotes: 1