Java对话框的空指针异常错误?

时间:2019-05-08 00:39:41

标签: java

我对Java还是很陌生,我试图遵循最简单的教程,但是我无法运行如此基本的东西。

我将应用程序缩减到最低限度,但仍然遇到问题。

Java:

import javax.swing.JOptionPane;
public class Test
{
    public static void main(String[] args)
    {
        JOptionPane.showMessageDialog(null, "Test Message");
    }
}

CLI:

LM:TestApp sbb$ java -version
java version "1.8.0_201"
Java(TM) SE Runtime Environment (build 1.8.0_201-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.201-b09, mixed mode)

LM:TestApp sbb$ javac Test.java
LM:TestApp sbb$ java Test
Exception in thread "main" java.lang.NullPointerException
    at sun.font.FontDesignMetrics.getDefaultFrc(FontDesignMetrics.java:157)
    at sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:278)
    at sun.swing.SwingUtilities2.getFontMetrics(SwingUtilities2.java:1113)
    at javax.swing.JComponent.getFontMetrics(JComponent.java:1626)
    at javax.swing.plaf.basic.BasicGraphicsUtils.getPreferredButtonSize(BasicGraphicsUtils.java:276)
    at com.apple.laf.AquaButtonUI.getPreferredSize(AquaButtonUI.java:443)
    at com.apple.laf.AquaButtonUI.getMinimumSize(AquaButtonUI.java:431)
    at javax.swing.JComponent.getMinimumSize(JComponent.java:1744)
    at javax.swing.plaf.basic.BasicOptionPaneUI.addButtonComponents(BasicOptionPaneUI.java:693)
    at javax.swing.plaf.basic.BasicOptionPaneUI.createButtonArea(BasicOptionPaneUI.java:630)
    at com.apple.laf.AquaOptionPaneUI.createButtonArea(AquaOptionPaneUI.java:53)
    at javax.swing.plaf.basic.BasicOptionPaneUI.installComponents(BasicOptionPaneUI.java:178)
    at javax.swing.plaf.basic.BasicOptionPaneUI.installUI(BasicOptionPaneUI.java:141)
    at javax.swing.JComponent.setUI(JComponent.java:666)
    at javax.swing.JOptionPane.setUI(JOptionPane.java:1860)
    at javax.swing.JOptionPane.updateUI(JOptionPane.java:1882)
    at javax.swing.JOptionPane.<init>(JOptionPane.java:1845)
    at javax.swing.JOptionPane.showOptionDialog(JOptionPane.java:857)
    at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:666)
    at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:637)
    at javax.swing.JOptionPane.showMessageDialog(JOptionPane.java:608)
    at Test.main(Test.java:6)

我使用的版本与尝试运行的代码是否存在问题?

我找到了一个非常基本的教程,所有内容似乎也都可以匹配: http://www.java2s.com/Tutorial/Java/0240__Swing/CreateaMessageDialogBox.htm

我的环境有问题吗?

0 个答案:

没有答案