Results 1 to 4 of 4
  1. #1
    D-Rock is offline Member
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Default Null Pointer Exception Issue

    Alright, so in my code, I have a few images I need to display under certain circumstances. I just want a simple image display, so I'm using JLabels to display the images. So, when I add the JLabel of the image to my Panel from the constructor of the class, everything works fine. But when I move that same statement to either a method of the class or a subclass (like TimerListener) a NullPointerException gets thrown. Not sure what the issue is, because usually the issue seems to be with a missing file, and that can't be the case here.

    I would post the code, but It's rather long and cumbersome.

    Any ideas on how to correct this? Thanks.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    You've got the code, and you know where the NPE is occurring (the exception tells you), so you'll have to trace back in the code to see why the object you think has been initialized is null. There's not much more that we can do than cheer you on.

  3. #3
    D-Rock is offline Member
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Default

    That's just the problem. The error message says that the exception is occurring in the line that adds the label to the panel. As far as I know, there isn't any reason why an image that can be found in the class can't be used in a subclass. I guess I'll just look over it a few more times...

    Thanks.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Are you sure it's not the JPanel that's null? That's the object you're calling a method on, add(), not the JLabel. We can take wild stabs at guesses, like you're redeclaring the JPanel in the constructor or something like that, but without code, it's nothing more than a wild stab. Luck.

Similar Threads

  1. Null pointer Exception
    By peiceonly in forum New To Java
    Replies: 8
    Last Post: 09-05-2010, 07:48 PM
  2. Null pointer exception?
    By coffee in forum New To Java
    Replies: 4
    Last Post: 08-03-2009, 04:22 AM
  3. Help with null pointer exception
    By gammaman in forum New To Java
    Replies: 4
    Last Post: 07-14-2009, 01:23 AM
  4. null pointer exception
    By jyothi.priyanka in forum New To Java
    Replies: 12
    Last Post: 03-11-2009, 06:04 PM
  5. null pointer exception
    By cityguy503@yahoo.com in forum New To Java
    Replies: 4
    Last Post: 08-22-2008, 08:22 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •