-2
//Listener for the preorder button
jbtPreOrder.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e){
        key = Integer.parseInt(jtfKey.getText());
        if (!tree.isEmpty()){
            JOptionPane.showMessageDialog(null, "Enter something in the tree");
        }
        else {
            JOptionPane.showMessageDialog(null, key + " ");
            preorder(key.left);
            preorder(key.right);
        }
    }
}); 

In the preorder it says int cannot be dereferenced even when the variable is global.

takendarkk
  • 3,347
  • 8
  • 25
  • 37
Harsh Joshi
  • 1
  • 1
  • 2

2 Answers2

2

Key is a an int and int is a primitive. You cannot call methods on a primitive, only an object. Key should really be a string because you are calling get text and hence retrieving characters and not numbers....

user2226786
  • 111
  • 1
  • 8
  • @HarshJoshi We can't really read code that is posted in comments. Edit your question to add code and details. – takendarkk Nov 17 '14 at 04:11
0
        preorder(key.left);
        preorder(key.right);

Exactly the error it self explaining that here key is a primitive datatype (int). you are using primitive datatype (here int) key as a reference variable.

So,you cannot dereference using key since it is not holding any object.

Sagar Pudi
  • 4,634
  • 3
  • 32
  • 51