Results 1 to 3 of 3
  1. #1
    FlyNn is offline Senior Member
    Join Date
    Feb 2010
    Posts
    128
    Rep Power
    0

    Default JPanel NullPointerException

    Hi guys,

    So I want to update some panels on my GUI when a button gets pressed.
    I got action listener assigned and everything works - but.

    When I click a button the code gets an Panel object. This is my panel.

    Java Code:
    public class LoginPane extends JPanel{
    
        public LoginPane(){
    
            JButton test = new JButton("Login test");
    
            this.add(test);
    
        }
    }
    The action listener calls this method:

    Java Code:
    public static void loginPanel(){
    
            loginPane = new LoginPane();
    
            [B]content.add(loginPane, BorderLayout.CENTER);[/B]
    
            content.repaint();
    
            content.updateUI();
    
        }
    I've set line to bold that errors out.

    When I press a button, I get a compiler error:

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at GUI.MainFrame.loginPanel(MainFrame.java:77)
    at Listeners.LoginListener.actionPerformed(LoginListe ner.java:14)
    at javax.swing.AbstractButton.fireActionPerformed(Abs tractButton.java:1995)
    at javax.swing.AbstractButton$Handler.actionPerformed (AbstractButton.java:2318)
    at javax.swing.DefaultButtonModel.fireActionPerformed (DefaultButtonModel.java:387) etc....

    Any help would be appreciated.
    Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default

    content == null?

  3. #3
    FlyNn is offline Senior Member
    Join Date
    Feb 2010
    Posts
    128
    Rep Power
    0

    Default

    ahhh man, such a stupid mistake i made. :D Instead of adding to the frame, I kept adding to another JPanel(content)

    Thanks for making me realize that
    Measuring programming progress by lines of code is like measuring aircraft building progress by weight.

Similar Threads

  1. Adding Jpanel ontop of another Jpanel
    By Manfizy in forum AWT / Swing
    Replies: 4
    Last Post: 03-05-2011, 10:34 PM
  2. Placing a new JPanel over a paint overriden JPanel
    By Tanshaydar in forum AWT / Swing
    Replies: 4
    Last Post: 12-08-2010, 06:00 PM
  3. Replies: 1
    Last Post: 11-09-2010, 09:28 AM
  4. NullPointerException help me!
    By phancuong87 in forum New To Java
    Replies: 4
    Last Post: 01-19-2010, 04:01 PM
  5. NullPointerException I NEED HELP
    By mayhewj7 in forum New To Java
    Replies: 2
    Last Post: 02-13-2009, 08:03 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
  •