mardi 23 mai 2017

JSP throwing 500 error when reading ELSE statement

If my array has items in it the for loop executes fine but if it's empty and goes to the else I get a null pointer HTTP 500 error...what am I doing wrong?

<% out.print("<ul>");

         if(p.getToppings().length != 0) {    
        for (int x = 0; x < p.getToppings().length; x++) { 
        out.print("<li>");
            out.print(p.getToppings()[x]); 
            out.print("<br>");


        out.print("</li>");

        }

        } else {
        out.print("No Toppings"); 
        } %>

Aucun commentaire:

Enregistrer un commentaire