我试图捕获一个异常,然后在JTextArea中显示它,但是我得到了null...
这就是它:
} 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();
}当发生错误时,我会在JTextArea中得到以下代码:
Here is the reason why it crashed:
null为什么?
发布于 2010-08-21 04:33:57
因为异常rwe不包含消息。例如,NullPointerException通常就是这种情况。除了消息之外,您可能还希望包括异常类型(如果它有异常类型)。
发布于 2010-08-21 04:31:20
您正试图在JTextarea中显示异常消息。异常不需要有消息。也许这不是。
https://stackoverflow.com/questions/3534646
复制相似问题