Results 1 to 6 of 6
  1. #1
    Chaosje is offline Member
    Join Date
    May 2011
    Posts
    6
    Rep Power
    0

    Default [solved]exception: contentPane cannot be set to null.

    hey there,

    im a programmer thats new to the world of Java and im having an issue :S
    I'm trying to create a program, and it gives me the following error:
    "
    IllegalComponentStateException: contentPane cannot be set to null."

    i have no idea how i should be doin this, and dont know if its even possible the way ive programmed this so maybe you guys could give me a hand?

    thx in advance....

    Java Code:
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    
    /**
     *
     * @author Chaos
     */
    public class CronusApp extends JFrame implements ActionListener{
       private JMenuBar menubar;
        private JMenu Bestand, Opties;
        private JMenuItem Sluiten, Help;
        private Login loginpaneel;
        private KeuzePanel keuzepaneel;
    
    
        public CronusApp()
        {
            //hier even ingelogd bijgezet om te testen, als deze veranderd naar fals, verdwijnt het inlogscherm en komt het keuzepanel tevoorschijn
             boolean ingelogd = false;
    
          loginpaneel = new Login();
          if (ingelogd == true)
          {
              setContentPane(loginpaneel);
    
             //dit zijn de 2 menu keuzes
            menubar = new JMenuBar();
            Bestand = new JMenu("Bestand");
            Opties = new JMenu("Opties");
            menubar.add(Bestand);
            menubar.add(Opties);
    
            //dit zijn de knoppen in het menu
            Sluiten = new JMenuItem("Sluiten");
            Help = new JMenuItem("Help");
            Bestand.add(Sluiten);
            Opties.add(Help);
    
            Sluiten.addActionListener(this);
            Help.addActionListener(this);
    
            setJMenuBar(menubar);
          }
          if(ingelogd == false)
          {
              setContentPane(keuzepaneel);
          }
          
           
        }
    }
    p.s. i havent added the action performed, but they are somewhere down here, theyre just not part of the problem and i wanted to save you useless lines of code
    Last edited by Chaosje; 05-04-2011 at 10:48 PM. Reason: Solved

  2. #2
    ojn
    ojn is offline Senior Member
    Join Date
    Sep 2008
    Location
    Stockholm, Sweden
    Posts
    119
    Rep Power
    0

    Default

    It's guessing it's
    PHP Code:
    setContentPane(keuzepaneel);
    that's causing the error. keuzepaneel is never initialized and therefor null.

  3. #3
    Chaosje is offline Member
    Join Date
    May 2011
    Posts
    6
    Rep Power
    0

    Default

    so how should it be ? :$

    i thought naming the attribute and then placin the contentpane was enough :S
    since "keuzepaneel" is an instance of "KeuzePanel(a different class)".. or am I just understanding it wrong?

    if so ,

    how should it be ?

  4. #4
    Jodokus's Avatar
    Jodokus is offline Senior Member
    Join Date
    Jan 2011
    Location
    Amsterdam, the Netherlands
    Posts
    230
    Rep Power
    4

    Default

    since "keuzepaneel" is an instance of "KeuzePanel(a different class)".. or am I just understanding it wrong?
    Yes. you are. It is just a declaration of a variable of the proper type.
    Like ojn remarked you have to initialize it, e.g. by constructing it like:
    private KeuzePanel keuzepaneel = new KeuzePanel();
    provided this constructor exists. Only after that "keuzepaneel" is referencing an instance.

  5. #5
    Chaosje is offline Member
    Join Date
    May 2011
    Posts
    6
    Rep Power
    0

    Default

    Thank you, that totally clarified it for me :D
    you guys r the best :D

  6. #6
    Jodokus's Avatar
    Jodokus is offline Senior Member
    Join Date
    Jan 2011
    Location
    Amsterdam, the Netherlands
    Posts
    230
    Rep Power
    4

    Default

    ojn and I both have reputation 0 until now. :confused:
    Mark your thread as solved.
    Last edited by Jodokus; 05-04-2011 at 08:03 PM.

Similar Threads

  1. Null Pointer Exception HELP!?
    By 2wyked in forum New To Java
    Replies: 3
    Last Post: 04-04-2011, 02:41 AM
  2. Null pointer exception
    By samuel.roshni in forum Java Servlet
    Replies: 14
    Last Post: 01-22-2011, 03:25 PM
  3. Null pointer Exception
    By peiceonly in forum New To Java
    Replies: 8
    Last Post: 09-05-2010, 07:48 PM
  4. Null Pointer exception
    By diegoyj in forum New To Java
    Replies: 7
    Last Post: 01-29-2010, 05:17 PM
  5. Null Pointer Exception
    By andre1011 in forum Advanced Java
    Replies: 4
    Last Post: 02-07-2009, 04:30 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
  •