常见问题
包路径
注意java代码里面的包名
资源文件路径异常
问题出在ImageIcon的初始化上。NullPointerException表明在尝试创建ImageIcon时,传递给它的URL为null。这通常是因为资源文件没有正确加载。
解决:java -cp .;C:\Users\李恒\Desktop\code\java\GUI\resources SimpleCodeEditorTwo
C:\Users\李恒\Desktop\code\java\GUI>java SimpleCodeEditorTwo
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at javax.swing.ImageIcon.<init>(Unknown Source)
at ImageIconExample.<init>(SimpleCodeEditorTwo.java:36)
at SimpleCodeEditorTwo.createAndShowGUI(SimpleCodeEditorTwo.java:14)
at SimpleCodeEditorTwo.lambda$main$0(SimpleCodeEditorTwo.java:9)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
C:\Users\李恒\Desktop\code\java\GUI>