gpt4 book ai didi

java - 线程异常

转载 作者:行者123 更新时间:2023-12-01 17:27:48 25 4
gpt4 key购买 nike

    public class Intro extends JFrame implements ActionListener {
ImageIcon pic = new ImageIcon(this.getClass().getResource("cars-games.jpg"));
JLabel l1 = new JLabel();
Image car = pic.getImage();

public static void main (String[]args){
Intro i = new Intro();
i.show();
}
}

它给了我这个错误:

Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at Intro.<init>(Intro.java:15)
at Intro.main(Intro.java:58)

任何人都可以帮忙吗?

最佳答案

您的资源为空,并且不能使用空参数构造 ImageIcons。

确保您输入了“cars-games.jpg”的正确路径。

关于java - 线程异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13613209/

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