gpt4 book ai didi

Java - getMessage() 返回 null

转载 作者:行者123 更新时间:2023-12-01 06:48:04 26 4
gpt4 key购买 nike

我试图捕获异常然后将其显示在 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

为什么?

最佳答案

因为异常rwe不包含消息。例如,NullPointerException 就是典型的情况。除了消息之外,您可能还想包含异常类型(如果有的话)。

关于Java - getMessage() 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3534646/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com