Results 1 to 4 of 4
  1. #1
    richirich is offline Member
    Join Date
    Jan 2011
    Posts
    4
    Rep Power
    0

    Default Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

    Hello
    I am new to Java . I am trying to develop a GUI using swings , but I am getting the error "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException" while running the program I am trying to use Jtree to open folders stored in hard disk in tree format .
    its pointing the exception error in the following line of code
    cp.setLayout(new BoxLayout(cp, BoxLayout.X_AXIS));
    (java.lang.NullPointerException).

    Please help me regarding the same Thanks in advance

  2. #2
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Wink

    Can you post some more code please?

    We can't figure out from whatever you have provided here. From the code line and exception, seems like the cp variable was not declared/initialized properly.

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

  3. #3
    richirich is offline Member
    Join Date
    Jan 2011
    Posts
    4
    Rep Power
    0

    Default

    Here is the declaration

    JFrame frame;
    cp = frame.getContentPane();

  4. #4
    goldest's Avatar
    goldest is offline Senior Member
    Join Date
    Oct 2009
    Location
    Pune, India
    Posts
    469
    Rep Power
    5

    Wink

    Quote Originally Posted by richirich View Post
    JFrame frame;
    cp = frame.getContentPane();
    Where are you initializing the frame? This is simple declaration.

    Are you initializing it anywhere like,

    Java Code:
    frame = new JFrame();
    or something like that?

    If not, then NullPointerException is surely due, when you are trying to invoke anything on that frame.

    Goldest
    Java Is A Funny Language... Really!
    Click on * and add to member reputation, if you find their advices/solutions effective.

Similar Threads

  1. Replies: 1
    Last Post: 12-13-2010, 03:19 PM
  2. Replies: 5
    Last Post: 10-02-2010, 12:41 AM
  3. Replies: 3
    Last Post: 04-30-2010, 07:44 PM
  4. Replies: 4
    Last Post: 04-01-2010, 10:34 PM
  5. Replies: 5
    Last Post: 08-26-2009, 11:37 AM

Posting Permissions

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