提问人:Maz 提问时间:7/19/2022 最后编辑:nitindMaz 更新时间:7/19/2022 访问量:128
IntelliJ 与 Eclipse 中的 Java Swing 应用程序问题
Java Swing Application issue in IntelliJ vs Eclipse
问:
早在 2017 年,我就用 Java 创建了一个包含 GUI 的项目。当时我使用的是 Eclipse。我现在正在使用 IntelliJ 并尝试在那里重新创建项目。它在 Eclipse 中仍然运行良好,但是当我在 IntelliJ 中运行它时,我得到:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at java.desktop/javax.swing.ImageIcon.<init>(ImageIcon.java:217)
at Application.load(Application.java:619)
at Application.initActions(Application.java:549)
at Application.<init>(Application.java:47)
at Main$1.run(Main.java:14)
at java.desktop/java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:313)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:770)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:721)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:715)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:85)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:740)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:203)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
看起来它有问题的确切行是:
private ImageIcon load(final String name) {
return new ImageIcon(getClass().getResource("/icons/" + name + ".png"));
}
我没有更改文件夹图标的名称,也没有更改其中的文件。我错过了什么?
答:
1赞
Maz
7/19/2022
#1
阿布拉的问题实际上帮助我找到了答案。我在 src/main 中缺少一个文件夹及其文件。
评论
name
icons