Results 1 to 5 of 5

Thread: NullPointerException exception occures in "AWT-EventQueue-0"

  1. #1
    Join Date
    Jul 2009
    Posts
    79

    NullPointerException exception occures in "AWT-EventQueue-0"

    When I run my java program, I have this exception that bothers me:

    run:
    Exception in thread "AWT-EventQueue-0" Java. Lang. NullPointerException
    at CLEANFILES. RetagMp3. ReadMp3 (RetagMp3. java: 209)
    at CLEANFILES. RetagMp3. ReadInfoAlbum (RetagMp3. java: 98)
    at CLEANFILES. RetagMp3. RetagAlbum (RetagMp3. java: 80)
    at CLEANFILES. RetagMp3. RetagAllAlbums (RetagMp3. java: 65)
    at CLEANFILES. RenameMp3. jbtRetagMp3MouseClicked (RenameMp3. java: 163)
    at CLEANFILES. RenameMp3. access $ 100 (RenameMp3. java: 18)
    at CLEANFILES. RenameMp3 $ 2. mouseClicked (RenameMp3. java: 82)
    at java. awt. AWTEventMulticaster. mouseClicked (AWTEventMulticaster. java: 253)
    at java. awt. Component. processMouseEvent (Component. java: 6266)
    at javax. swing. JComponent. processMouseEvent (JComponent. java: 3267)
    at java. awt. Component. processEvents (Component. java: 6028)
    at java. awt. Container. processEvents (Container. java: 2041)
    at java. awt. Component. dispatchEventImpl (Component. java: 4630)
    at java. awt. Container. dispatchEventImpl (Container. java: 2099)
    at java. awt. Component. dispatchEvent (Component. java: 4460)
    at java. awt. LightweightDispatcher. retargetMouseEvent (Container. java: 4574)
    at java. awt. LightweightDispatcher. processMouseEvent (Container. java: 4247)
    at java. awt. LightweightDispatcher. dispatchEvent (Container. java: 4168)
    at java. awt. Container. dispatchEventImpl (Container. java: 2085)
    at java. awt. Window. dispatchEventImpl (Window. java: 2475)
    at java. awt. Component. dispatchEvent (Component. java: 4460)
    at java. awt. EventQueue. dispatchEvent (EventQueue. java: 599)
    at java. awt. EventDispatchThread. pumpOneEventForFilters (EventDispatchThread. java: 269)
    at java. awt. EventDispatchThread. pumpEventsForFilter (EventDispatchThread. java: 184)
    at java. awt. EventDispatchThread. pumpEventsForHierarchy (EventDispatchThread. java: 174)
    at java. awt. EventDispatchThread. pumpEvents (EventDispatchThread. java: 169)
    at java. awt. EventDispatchThread. pumpEvents (EventDispatchThread. java: 161)
    at java. awt. EventDispatchThread. run (EventDispatchThread. java: 122)
    I do not really know where to start so there are lines. If some can enlighten me directly or can tell me what is the problem.

    Here is the code of my function ReadMp3:

    Code:
        public static tAlbum ReadMp3 (tInfoAlbums InfoAlbums, tAlbum Album)
        {
            File PathDirMp3 = new File(InfoAlbums.PathAlbum+"\\"+InfoAlbums.CurrentAlbum);
            File [] TrackList = PathDirMp3.listFiles();
             String [] Fields;
            for(int i=0 ; i<TrackList.length ; i++)
            {
                if(IsMp3(TrackList[i].getName()))
                {
                    Fields = TrackList[i].getName().split(" - ");
                    Album.Track[i].NoTrack = Fields[0];
                    Album.Track[i].Title = Fields[2];
                }
            }
            return Album;
        }
    I give you also my "types":

    Code:
        static class tInfoAlbums{
            public String Genre;
            public String PathAlbum;
            public boolean TypeAlbum;
            public String CurrentAlbum;
        }
     
        static class tTrack {
            String NoTrack;
            String Title;
        }
     
        static class tAlbum {
            int Year;
            String Artist;
            String Album;
            tTrack [] Track;
            File Picture;
        }

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: NullPointerException exception occures in "AWT-EventQueue-0"

    The problem came from line 209 in file RetagMP3 method ReadMP3. It is a NullPointerException, ie you call a method on a null object.

    In your "for": "PathDirMp3.length ()", it does not work I think

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: NullPointerException exception occures in "AWT-EventQueue-0"

    Yes it's true!

    I'll offer four solutions:

    A) Album is null, it must look in the calling method to see what is passed as parameter
    B) Album.Track is null. Must initialize the array before accessing any of its boxes
    C) Album.Track [i] is null. Must initialize each box before the change.
    D) The answer D.

    Let me add something:

    Code:
    Album.Track[i].NoTrack = Fields[0];
    Album.Track[i].NoTrack = Fields[1];
    Album.Track[i].Title = Fields[2];

  4. #4
    Join Date
    Jul 2009
    Posts
    79

    Re: NullPointerException exception occures in "AWT-EventQueue-0"

    Thank you, I changed the loop in my code. Thank you for naming conventions if you have a site that would help me then please help me. But the error persists! So I agreed, after checking, my table is not initialized. But I counted the initialized when I put the values inside. How can I do in this method to initialize with the number of files found?

  5. #5
    Join Date
    Apr 2008
    Posts
    2,005

    Re: NullPointerException exception occures in "AWT-EventQueue-0"

    Code:
    Album. Track = new tTrack [ TrackList. length ] ;
    A place just before your loop.

    Also at the beginning of each iteration of the loop, you also have to initialize each cell with
    Code:
    Album. Track [ i ] = new tTrack ( ) ;
    For conventions, in brief:
    - Variables and method names begin with a lowercase
    - The upper classes by a (somewhat the opposite of what you did in fact )

    There are others but those two already greatly clarify your code!

Similar Threads

  1. Replies: 7
    Last Post: 09-10-2011, 11:14 PM
  2. Replies: 6
    Last Post: 30-07-2011, 01:18 PM
  3. Replies: 4
    Last Post: 05-04-2011, 03:27 AM
  4. Replies: 7
    Last Post: 15-01-2011, 10:53 AM
  5. Replies: 5
    Last Post: 20-10-2010, 12:44 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,730,974.39833 seconds with 16 queries