这是我的追溯
Oct 9, 2012 3:58:44 PM org.jdesktop.application.Application$1 run
SEVERE: Application class sampleapp.SampeAppApp failed to launch
java.lang.NullPointerException
at sampleapp.SampeAppView.<init>(MusicDownloaderView.java:89)
at sampleapp.SampeAppApp.startup(MusicDownloaderApp.java:18)
at org.jdesktop.application.Application$1.run(Application.java:171)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:682)
at java.awt.EventQueue.access$000(EventQueue.java:85)
at java.awt.EventQueue$1.run(EventQueue.java:643)
at java.awt.EventQueue$1.run(EventQueue.java:641)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:652)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Exception in thread "AWT-EventQueue-0" java.lang.Error: Application class musicdownloader.MusicDownloaderApp failed to launch
at org.jdesktop.application.Application$1.run(Application.java:177)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:682)
at java.awt.EventQueue.access$000(EventQueue.java:85)
at java.awt.EventQueue$1.run(EventQueue.java:643)
at java.awt.EventQueue$1.run(EventQueue.java:641)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:652)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:296)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
Caused by: java.lang.NullPointerException
我所有标记的事件都是
jPanel1.removeAll();
第89行
jButton1.addActionListener(new ActionListener() {
任何想法如何解决这个问题?我也在网上搜索找到任何帮助,但我没有找到任何东西。所有答案都表示赞赏。 提前谢谢
答案 0 :(得分:1)
你有没有初始化jButton1?
由于NullPointerException出现在第89行,因此jButton1可能为null。
可以肯定的是,只需尝试System.out.println(jButton1);
,如果它打印出Null,则表示您没有正确初始化它。
我不知道是不是这样,但是如果是这样的话,请避免使用JButton jButton1 = null;
之类的变量声明,而是使用JButton jButton1;
,因为通过初始化一个带有null的变量,你会阻止编译器每当忘记初始化对象时都会发出警告。
答案 1 :(得分:0)