Re: Strange NullPointerException
[email protected] Tue, 24 May 2005 11:43:06 -0400
| Newsgroups | gmane.comp.embedded.carlsbad-cubes |
|---|---|
| Message-ID | <OF7E8849A0.A464E4F2-ON8525700B.0054FE38-8525700B.005657F2@bureauveritas.com> |
The reason is because your variable named p_config is null and never
initialized. Before the line,
p_config.setToolTipText("JUPPIE");
you need lookup the object that was created by the swing engine, like this,
p_config= (JPanel)ui.find("p_config_object_ID_from_xml_file");
The engine does not automatically initialize your objects. It creates
internal ones.
Best Regards,
Tom Woiccak
|---------+------------------------------->
| | Forum@carlsbadcubes.|
| | com |
| | Sent by: |
| | Forum-bounces@carlsb|
| | adcubes.com |
| | |
| | |
| | 05/23/2005 08:25 AM |
| | Please respond to |
| | List for Users of |
| | Carlsbad Cubes' |
| | Technologies and |
| | Products |
| | |
|---------+------------------------------->
>----------------------------------------------------------------------------------------------------------------------|
| |
| To: [email protected] |
| cc: |
| Subject: [Forum] Strange NullPointerException |
| Ref.: |
>----------------------------------------------------------------------------------------------------------------------|
Hello,
I have taken one of the Swixml examples to write my own small Swing App.
The
GUI renders fine, but when implementing my first action I ran into a
NullPointer exception... Here's my code:
public class ConfigBuilderUI extends WindowAdapter implements
ActionListener{
private SwingEngine ui;
private JButton b_button;
private JPanel p_config;
public static void main(String[] args) throws Exception{
new ConfigBuilderUI();
}
public AbstractAction submit = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
//TODO: Some action takes place
}
};
public ConfigBuilderUI() throws Exception{
//Create ui
ui = new SwingEngine(this);
ui.render("xml/configbuilder.xml");
//Init GUI components
p_config.setToolTipText("JUPPIE");
//Set visible
ui.getRootComponent().setVisible(true);
}
/**
* Invoked when an action occurs.
*/
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
if ("AC_FILE_SELECT".equals( command )) {
System.out.println("Button clicked!");
}
}
}
...when trying to "p_config.setToolTipText("JUPPIE");" the app throws the
following exception:
java.lang.NullPointerException
at com.configbuilder.ui.ConfigBuilderUI.<init>(ConfigBuilderUI.java:50)
at com.configbuilder.ui.ConfigBuilderUI.main(ConfigBuilderUI.java:32)
Exception in thread "main"
I cannot understand this, because the documention says, that the gui
components are initialized automatically.
I will appreciate any hints! Thanks in advance,
Sebastian
_______________________________________________
Forum mailing list
[email protected]
http://carlsbadcubes.com/mailman/listinfo/forum_carlsbadcubes.com