Search code examples
javaphperror-handlingidentifier

I get "<identifier> expected" For my code and i don't understand why my code isn't working


The issue is that it says Identifier Expected but i don't know whats expected

public class TTester 
    { 
    public static void main(String args[]) // main
    { 
    //the first integer in the tree is used to create the object 
       BST bstObj = new BST(50); // creating the object
       bstObj.addNode(56); 
       bstObj.addNode(52);     
       bstObj.addNode(25); //The numbers added
       bstObj.addNode(74); 
       bstObj.addNode(54); 
    } 
        bstObj.traverseAndPrint(bstObj.rootNode); // wanting to print the program
    } 

Solution

  • In JAVA all executable statement must be inside a method/block only. Your following statement is not part of any method/block:

    bstObj.traverseAndPrint(bstObj.rootNode); 
    

    Try moving it inside the main method and test.