I have a problem in my code when I am creating a table in Java using HTML. This is my code:
for(int station : stations){
String rowcolor = null;
String stationnum = Integer.toString(station);
String lastDate = pollData(station); //CALL GET LAST
String status = determineStatus(station, lastDate); // CALL DETERMINE STATUS
switch(status){
case " ONLINE":
rowcolor = (" <tr bgcolor=\"#5FFF33\">");
break;
case " OFFLINE":
rowcolor = (" <tr bgcolor=\"red\">");
break;
case " DELAYED":
rowcolor = (" <tr bgcolor=\"yellow\">");
break;
}
out.write("<html>" +
"<body>" +
"<table border ='1'>" +
"<tr>" +
"<td>Station Number</td>" +
"<td>Station Name</td>" +
"<td>Status</td>" +
"<td>As of Date</td>" +
"</tr>");
out.write(rowcolor + "<td>");
out.write(stationnum);
out.write("</td><td>");
out.write(stationnname[id]);
out.write("</td><td>");
out.write(status);
out.write("</td><td>");
out.write(lastDate);
out.write("</table>" +
"</body>" +
"</html>");
id++;
out.close();
}
}catch (IOException e) {
System.err.println(e);
}
and this is the output:
When I remove the out.close(); part, the output is this:
As you can see, the image there is a problem in creating the table. Something is not right but I can’t find a way to fix it. Please help me; thanks in advance.

