0

I wrote an array but it crashes once I try to access a certain webpage. I'm also using a tomcat server and Servlets. I backtracked it and found it at line 114 which is a piece of Java code.

I'm trying to print certain info that people give when they register in my webapp as an overview on another webpage which it does when I press the register button. But what a navigate manually to it crashes.

Can someone help me figure out what I did wrong in that piece of code? Thanks in advance.

114:ArrayList<Registratie> leden = (ArrayList) request.getAttribute("leden");
    String result="";
    for(Registratie Registratie:leden){
        result = result +  " <tr> <th>" + Registratie.getNaam() +"</th> \n" + "<th>" + Registratie.getAchternaam() + "</th> \n" + "<th>"
                + Registratie.getLoginnaam() + "</th> \n" + "<th>" + Registratie.getEmail() + "</th> \n" + "<th>" + Registratie.getNiveau()+"</th>" +"</tr>" + "\n";
    }

photo of register process: https://i.stack.imgur.com/nYpR3.jpg

photo of database: https://i.stack.imgur.com/R2aMD.jpg

When I click on "leden overzicht" which should show an overview of all those that registered: https://i.stack.imgur.com/n3uxJ.jpg

rainer
  • 3,295
  • 5
  • 34
  • 50
pieterjan
  • 1
  • 2
  • 1
    Based on everything you have posted, I would assume you forgot to set the `request` attribute `leden` (thus it is null). If you need more help, **edit** your question into a minimal, complete and reproducible example. – Elliott Frisch Mar 11 '20 at 19:28
  • 1
    Your foreach loop has wrong syntax. – Ilya Lysenko Mar 11 '20 at 19:33
  • @IlyaLysenko Why do you believe that enhanced `for` loop is invalid? `for (Registratie Registratie : leden)` is perfectly valid, though the loop variable *should* be spelled with lowercase (`registratie`). – Andreas Mar 11 '20 at 19:38

0 Answers0