Reputation: 18198
I'm trying to catch an exception then display it in a JTextArea but I am getting null...
Here it is:
} catch (Exception rwe) {
// System.exit(0);
game.remove(yPanel);
game.remove(xPanel);
game.remove(roomPanel);
game.remove(userPanel);
game.remove(titlePanel);
game.remove(introPanel);
remove(game);
remove(sp);
remove(invOne);
remove(main);
remove(say);
add(statusPanel);
JTextArea errorText = new JTextArea();
errorText.append("Here is the reason why it crashed:\n" +rwe.getMessage());
errorText.setPreferredSize(new Dimension(500,300));
System.out.println("errorrr:" + rwe.getMessage());
statusPanel.add(errorText);
statusPanel.setOpaque(true);
labelStatus.setVisible(true);
System.out.println("Server crashed");
c.append("\nServer crashed...");
rwe.printStackTrace();
}
and when an error happens I get this inside the JTextArea:
Here is the reason why it crashed:
null
Why?
Upvotes: 0
Views: 6030
Reputation: 25491
Because the exception rwe
doesn't include a message. This is typically the case with a NullPointerException
, for instance. You might want to include the exception type in addition to the message (if it has one).
Upvotes: 9
Reputation: 93177
You're trying to display the message of an exception in the JTextarea. An exception doesn't need to have a message. Maybe this doesn't.
Upvotes: 1