Results 1 to 6 of 6
- 05-04-2011, 04:25 PM #1
Member
- Join Date
- May 2011
- Posts
- 6
- Rep Power
- 0
[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....
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 codeJava 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); } } }Last edited by Chaosje; 05-04-2011 at 09:48 PM. Reason: Solved
- 05-04-2011, 04:40 PM #2
Senior Member
- Join Date
- Aug 2008
- Location
- Stockholm, Sweden
- Posts
- 119
- Rep Power
- 0
It's guessing it's
that's causing the error. keuzepaneel is never initialized and therefor null.PHP Code:setContentPane(keuzepaneel);
- 05-04-2011, 05:33 PM #3
Member
- Join Date
- May 2011
- Posts
- 6
- Rep Power
- 0
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 ?
- 05-04-2011, 05:49 PM #4
Yes. you are. It is just a declaration of a variable of the proper type.since "keuzepaneel" is an instance of "KeuzePanel(a different class)".. or am I just understanding it wrong?
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.
- 05-04-2011, 05:57 PM #5
Member
- Join Date
- May 2011
- Posts
- 6
- Rep Power
- 0
Thank you, that totally clarified it for me :D
you guys r the best :D
- 05-04-2011, 06:53 PM #6
Similar Threads
-
Null Pointer Exception HELP!?
By 2wyked in forum New To JavaReplies: 3Last Post: 04-04-2011, 01:41 AM -
Null pointer exception
By samuel.roshni in forum Java ServletReplies: 14Last Post: 01-22-2011, 02:25 PM -
Null pointer Exception
By peiceonly in forum New To JavaReplies: 8Last Post: 09-05-2010, 06:48 PM -
Null Pointer exception
By diegoyj in forum New To JavaReplies: 7Last Post: 01-29-2010, 04:17 PM -
Null Pointer Exception
By andre1011 in forum Advanced JavaReplies: 4Last Post: 02-07-2009, 03:30 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks