最近在看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的实例,必须分配一个合适的内部类E的实例(如x.new A(),x必须是E的实例。)看着这句提示,我就纳闷了,我已经用new实例化了这个类,为什么还不行呢。
于是百度谷歌了一下相关资料。原来我写的内部类是动态的,也就是开头以public class开头。而主程序是public static class main。在Java中,类中的静态方法不能直接调用动态方法。只有将某个内部类修饰为静态类,然后才能够在静态类中调用该类的成员变量与成员方法。所以解决办法是将public class改为public static class.
from:http://terry0501.iteye.com/blog/1774693
相关推荐
Java编程语言中的"No enclosing instance of type"错误通常发生在尝试创建非静态内部类的实例,但没有一个外部类的实例可以访问时。在上述示例中,`ListNode`是`PrintListFromTailToHead`类的非静态内部类。由于`...
在Java中,当你尝试在静态上下文中创建非静态内部类的对象时,会遇到以下错误信息:“No enclosing instance of type EmployeeTest is accessible. Must qualify the allocation with an enclosing instance of type...
-e 所有(every),比a更详细。 -f 取消保护。 -i 添加提示。 -p 强制执行。 -r 目录管理。 分屏显示的中途操作 空格<space> 继续打开下一屏; 回车<return> 继续打开下一行; b 另外开上一屏; f 另外开...
The main reason for making a virtual function inline is to place its definition in the class, either for convenience or to document its behavior, e.g., for accessors and mutators. The -inl.h Files...
Generators are a special type of function that can pause and resume execution, allowing the generation of values on demand. They use the `yield` keyword to produce a sequence of values. For instance: ...
F2084 Internal Error SCR765.00 of 5 Closed11193 Inlined function affects working of the enclosing for loop0.00 of 5 Closed11184 [Fatal Error] F2084 Internal Error: ILLK26340.00 of 5 Closed11069 ...
private static final ${enclosing_type} m_instance = new ${enclosing_type}(); /** * 私有的默认构造子 */ private ${enclosing_type}() {} /** * 静态工厂方法 */ public static ${enclosing_type}...
This importance of embedded systems is so far not well reflected inmany of the current curricula. This book is intended as an aid for changing this situation. It provides the material for a first ...
is just a sample of the Windows 95/98 type enhancements Calmira provides to the Windows 3.1 user interface... Taskbar with versatile Start Menu, nested to any level Wastepaper bin to store deleted ...
Android 中LayoutInflater.inflate()方法的介绍 Android 中LayoutInflater.inflate()方法是Android开发中最常用的方法之一,用于将布局文件转换成View对象。该方法是LayoutInflater类中的一个成员方法,主要用于将...
数控等离子切割技术资料The user is responsible for installing and using the plasma equipment according to the manufacturer’s instructions. If electromagnetic disturbances are detected then it shall be...
For instance, if you want to print today's date in a sentence, you would use `$ echo "Today is `date`"`. Here, `date` inside backticks is executed first to get the current date, which is then printed...
If the decimal representation has a repeating sequence of digits, indicate the sequence by enclosing it in brackets. For example, 1/3 = .33333333...is denoted as 0.(3), and 41/333 = 0.123123123...is ...
The first parameter is the pointer to the LUA state, the second parameter is the number of arguments on the stack that the command takes (and when executing a loaded script this can remain 0)....
编辑 Select Enclosing Element Alt+Shift+向上键 Editing in Structured Text Editors 编辑 选择外层元素 Alt+Shift+向上键 编辑 Java 源代码 编辑 Restore Last Selection Alt+Shift+向下键 Editing in Structured...
1. 题目中的选项涉及动词搭配,正确答案是D.enclosing,表示随信附上。这反映了商务信函中常见的表达方式。 2. 产品类别(categories)是市场营销中的术语,指公司生产的产品种类或分类,了解产品类别有助于制定...
- 进一步阐述:添加第三点原因,如"Thirdly, the cost-effectiveness of e-learning compared to traditional classrooms is another driving force." - 结果段:描述现象带来的结果,如"As a result, a growing ...
Inner classes can access private members of the enclosing class: - **Member Inner Classes**: Declared inside a class but outside any method. - **Local Inner Classes**: Declared inside a method. - **...