0

这是我的回溯

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() {

任何想法如何解决这个问题?我也在网上搜索以找到任何帮助,但我没有找到任何帮助。感谢所有答案。先感谢您

4

2 回答 2

1

你初始化jButton1了吗?由于 NullPointerException 发生在第 89 行,因此 jButton1 可能为空。可以肯定的是,简单地尝试一下System.out.println(jButton1);,如果它打印出 Null,则意味着您没有正确初始化它。

我不知道是不是这样,但如果是这样,请避免JButton jButton1 = null;使用, 之类的变量声明JButton jButton1;,因为通过使用 null 初始化变量,您可以防止编译器在您忘记初始化对象时向您发出警告。

于 2012-10-09T13:27:59.333 回答
0

你需要调试你的代码:

基本的 Netbeans 调试

使用 Netbeans 调试 Java 应用程序

于 2012-10-09T13:31:47.473 回答