[Java A] – is not an enclosing class

public class A {
public class B {

}
};

需要实例B类时,按照正逻辑是,A.B ab = new A.B();
那么编译器就会出现一个错误–“is not an enclosing class”
再翻看相关的java代码,发现原来写法出错了!正确的做法是
A a = new A();
A.B ab = a.new B();

没有静态(static)的类中类不能使用外部类进行.操作,必须用实例来进行实例化类中类.

时间: 2024-08-08 13:58:06

[Java A] – is not an enclosing class的相关文章

Java编译时出现No enclosing instance of type XXX is accessible.

今天在编译Java程序的时候出现以下错误: No enclosing instance of type Main is accessible. Must qualify the allocation with an enclosing instance of type Main (e.g. x.new A() where x is an instance of Main). 我原来编写的源代码是这样的: public class Main {class Dog //定义一个“狗类”{privat

eclipse中统计代码行数或代码量

打开File Search对话框, 选中正则表达式,在搜索文本框输入 /n 文件名称输入 *.java 在范围里选中Enclosing projects 然后就可以统计出整个项目的代码行数.

用Eclipse 统计代码行数小技巧

今天公司SQA问我目前项目代码行数有多少,我当时就是想,以前好像写过类似的统计工具但是一时又找不到 公司网络又不能下载,所以想想eclipse是不是又类似功能,找了下没有,但突然一想有一个转弯方法:统计工程里面的\n个数 1. 按 CTRL+H 打开查找对话框 选择file search 按下图方式输入 注意: I. 输入查找\n, 勾选正则式选项 II. 输入文件匹配, *.java是所有java文件 III. 勾选 Enclosing projects 代表当前项目 点击Search 就可以

(转)用Eclipse 统计代码行数小技巧

今天公司SQA问我目前项目代码行数有多少,我当时就是想,以前好像写过类似的统计工具但是一时又找不到 公司网络又不能下载,所以想想eclipse是不是又类似功能,找了下没有,但突然一想有一个转弯方法:统计工程里面的\n个数 1. 按 CTRL+H 打开查找对话框 选择file search 按下图方式输入 注意: I. 输入查找\n, 勾选正则式选项 II. 输入文件匹配, *.java是所有java文件 III. 勾选 Enclosing projects 代表当前项目 点击Search 就可以

eclipse相关技巧总结

原文:http://licoolxue.iteye.com/blog/619983 eclipse作为被广泛使用的ide,基本的使用技巧每个人都会一些,然而可能并未充分发掘其潜力,也许我们并没有真正认识这个常常打交道的家伙,工欲善其事必先利其器,把找到的eclipse的一些使用技巧转过来备份纪录,也希望能方便大家(文章结构可能有点乱) eclipse 代码行统计 统计总代码行: 打开File Search对话框, 选中正则表达式,在搜索文本框输入 \n 文件名称输入 *.java 在范围里选中E

Java 出现 No enclosing instance of type Test1 is accessible.(转,自己也遇到了!)

最近在看Java,在编译写书上一个例子时,由于书上的代码只有一部分,于是就自己补了一个内部类.结果编译时出现: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 instance of E). E指代我写的那个内部类. 根据提示,没有可访问的内部类E的实例,必须分配一

Java中出现No enclosing instance of type XXX is accessible问题

Java编写代码过程中遇到了一个问题,main方法中创建内部类的实例时,编译阶段出现错误,查看错误描述: Multiple markers at this line - The value of the local variable test is not used - No enclosing instance of type StaticCallDynamic is accessible. Must qualify the allocation with an enclosing insta

java解决 No enclosing instance of type XXX is accessible的问题

有些时候我们要把Activity的一些实现类移到java类里来实现,比如把写以下两个类: 在LifeCircle这个类中: public class LifeCircle { public class Mybroadcast extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { } } } 如果在Activity这样去new: public class Setti

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 E is accessible. Must qualify the allocation with an enclosing ins