No enclosing instance of type 类名 is accessible. Must qualify the allocation with an enclosing instan
2016-08-14 22:21
676 查看
下面是我写的代码,一个经典的内部类
public class Value{
public static void main(String[] args) {
Test y=new Test();
}
class Test{
public Test() {
System.out.println("yes");
}
}
}结果在编译阶段就报错了:
No enclosing instance of type
Value(类名) is accessible. Must qualify the allocation with an enclosing instance of type Value (e.g. x.new A() where x is an instance of Value).
没有可访问的内部类Value的实例,必须分配一个合适的内部类E的实例(如x.new A(),x必须是Value的实例。)
原来是因为我写的Value类是动态的,而public
static void main方法是静态的,我们没办法在静态方法内去实例化一个动态对象
因此最简单的方法就是把class Test 换成 static class Test
或者在别的动态方法内调用动态方法
public class Value{
public static void main(String[] args) {
Test y=new Test();
}
class Test{
public Test() {
System.out.println("yes");
}
}
}结果在编译阶段就报错了:
No enclosing instance of type
Value(类名) is accessible. Must qualify the allocation with an enclosing instance of type Value (e.g. x.new A() where x is an instance of Value).
没有可访问的内部类Value的实例,必须分配一个合适的内部类E的实例(如x.new A(),x必须是Value的实例。)
原来是因为我写的Value类是动态的,而public
static void main方法是静态的,我们没办法在静态方法内去实例化一个动态对象
因此最简单的方法就是把class Test 换成 static class Test
或者在别的动态方法内调用动态方法
相关文章推荐
- No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing instance of type E(e.g. x.new A() where x is an
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosing instance of type SimpleTh
- java中No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- java编译错误No enclosing instance of type TestFrame is accessible. Must qualify the allocation with an enclosing instance of type TestFrame (e.g. x.new A(
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosing instance of type SimpleTh
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosing instance of type SimpleTh
- <java>No enclosing instance of type GraphicFrame is accessible. Must qualify the allocation with an
- No enclosing instance of type A is accessible. Must qualify the allocation with an enclosin
- <java>No enclosing instance of type GraphicFrame is accessible. Must qualify the allocation with an
- 【Java-bug】No enclosing instance of type Test is accessible. Must qualify the allocation with an encl
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosing instance of type
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosing instance of type SimpleTh
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- - No enclosing instance of type Test is accessible. Must qualify the allocation with an enclosing in
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- No enclosing instance of type Monster is accessible. Must qualify the allocation with an enclosing i
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- Java编译错误“No enclosing instance of type AA is accessible. Must qualify the allocation with an enclosing instance of type SimpleT