[英]Non-static variable this cannot be referenced from a static context JFrame
[英]non-static variable cannot this be referenced from a static context error
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{
我看了几个示例,我注意到一个常见的答案是在main()中创建对象的新实例,但是我仍然遇到相同的错误,并且不清楚原因。
如果ExpressionTree
是与main()
方法相同的类的内部类,则可能的问题在于它不是静态的。 非静态内部类只能在非静态代码中实例化...请参阅:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.