NullPointerException with JTree.setModel()

Hi,

I am getting a Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException with the following code:

public class JTreeTest extends javax.swing.JFrame {

public JTreeTest() {

String Test = "Top Node";

DefaultMutableTreeNode TopNode = new DefaultMutableTreeNode(Test, true);

DefaultTreeModel TheTree = new DefaultTreeModel(TopNode);

// This is the instruction causing the issue...

jTree1.setModel(TheTree);

}

public static void main(String[] args) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

JTreeTest TheTest = new JTreeTest();

TheTest.setVisible(true);

}

});

}

private void initComponents() {

jScrollPane1 = new javax.swing.JScrollPane();

jTree1 = new javax.swing.JTree();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jScrollPane1.setBorder(null);

jTree1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));

jTree1.setAutoscrolls(true);

jScrollPane1.setViewportView(jTree1);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(layout.createSequentialGroup()

.addContainerGap()

.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 192, Short.MAX_VALUE)

.addContainerGap())

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()

.addContainerGap()

.addComponent(jScrollPane1)

.addContainerGap())

);

pack();

}

private javax.swing.JScrollPane jScrollPane1;

private javax.swing.JTree jTree1;

}

I can't figure out what I am doing wrong... Any one has ideas? Thanks !!!

[2073 byte] By [AdamMan71a] at [2007-11-27 3:45:18]
# 1
The jTree1 variable is null. Set it to something before you execute that line of code.
DrClapa at 2007-7-12 8:49:00 > top of Java-index,Java Essentials,Java Programming...
# 2
How can I be so stupid? I accidentally erased the initComponents() instruction at the beginning of my JTreeTest() constructor... I'll kick myself for that, promised !!!Thanks for pointing this out...
AdamMan71a at 2007-7-12 8:49:00 > top of Java-index,Java Essentials,Java Programming...