Crystal Cruises
Crystal Cruises

Reputation: 41

java.lang.NullPointerException bug when trying to run an app on netbeans

Here is my traceback

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

also all my marked occurrences is

 jPanel1.removeAll();

Line 89 is

 jButton1.addActionListener(new ActionListener() {

Any ideas how to solve this ? I also searched online to find any help but i didn't found anything. All answers are appreciated. Thank you in advance

Upvotes: 0

Views: 2177

Answers (2)

raspayu
raspayu

Reputation: 5139

You need to DEBUG your code:

Basic Netbeans debuging

Debug Java Applications with Netbeans

Upvotes: 0

lucasls
lucasls

Reputation: 1649

Have you initialized jButton1? Since the NullPointerException occurs an line 89, jButton1 is probably null. To be sure, try simply System.out.println(jButton1);, if it prints out Null, it means you didn't initialize it correctly.

I don't know if it's the case, but if it is, avoid variable declarations like JButton jButton1 = null;, using JButton jButton1; instead, because by initializing a variable with null you're preventing the compiler to warn you whenever you forget to initialize an object.

Upvotes: 1

Related Questions