2013-04-17 52 views
0
public static void main(String[] args) { 

Scanner input = new Scanner(System.in); 
System.out.println("Enter expression: "); 
String exp = input.nextLine().trim(); 

ExpressionTree exptree = new ExpressionTree1(); //new instance of ExpressionTree 
TreeNode root = new TreeNode(); 
root = exptree.parseOutsideExpression(exp); 
int evaluate = exptree.Compute(root); 
String answer = Integer.toString(evaluate); 
System.out.println("The evaluated expression is:" + answer); 

} 

class ExpressionTree{ 

我看幾個例子來參考和我注意到一個共同的答案是創建對象的內主)的新實例(這是我已經完成了,但是我仍然得到同樣的錯誤,我不清楚爲什麼。非靜態變量不能這樣從靜態上下文錯誤

+2

哪一行,你得到的錯誤在哪裏?該行的內容是什麼? – Justin

+2

你可以刪除reeNode root = new TreeNode(); 如果你只是將它重新分配一行後 –

+0

你需要有你的主要方法在一些類 – codeMan

回答

相關問題