No enclosing instance of type 类名 is accessible. Must qualify the allocation with an enclosing instan
来源:互联网 发布:安徽芜湖java 编辑:程序博客网 时间:2024/06/06 19:05
下面是我写的代码,一个经典的内部类
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 typeValue(类名) 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
或者在别的动态方法内调用动态方法
0 0
- No enclosing instance of type 类名 is accessible. Must qualify the allocation with an enclosing instan
- - No enclosing instance of type Test is accessible. Must qualify the allocation with an enclosing in
- No enclosing instance of type Monster is accessible. Must qualify the allocation with an enclosing i
- No enclosing instance of type ChuangKou is accessible. Must qualify the allocation with an enclosing
- No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing instanc
- No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- No enclosing instance of type X is accessible. Must qualify the allocation with an enclosing
- No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing
- No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing instanc
- No enclosing instance of type X is accessible. Must qualify the allocation with an enclosing instanc
- No enclosing instance of type Test is accessible. Must qualify the allocation with an enclosing inst
- No enclosing instance of type Outer is accessible. Must qualify the allocation with an enclosing ins
- No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing insta
- No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing instanc
- No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing instanc
- No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing instanc
- No enclosing instance of type * is accessible. Must qualify the allocation with an enclosing instanc
- 重载(overload)
- python中threading的setDaemon、join的用法(未完,待续)
- 四种方案解决ScrollView嵌套ListView问题
- print2flash实现将word文档转换成swf,网页直接预览
- 文章标题
- No enclosing instance of type 类名 is accessible. Must qualify the allocation with an enclosing instan
- android 常用图片处理效果总结
- 再次领悟设计模式-职责链
- 机器学习入门 之 概论
- 内部类
- HDU 2504 又见GCD【GCD】
- suse11 安装jdk1.7.0.79
- 次优查找树的原理是什么?
- Python学习之路(一)