No enclosing instance of type xxx is accessible
2015-07-25 11:36
288 查看
No enclosing instance of type test5 is accessible. Must qualify the allocation with an enclosing instance of type test5 (e.g. x.new A() where x is an instance of test5).在一个类里面的main函数,经常会写一些测试代码。在调用这个类里面的内部类的时候,出现不能初始化内部类的对象实例。发现两种解决方法:1、把内部类换成静态类2、直接把在main函数初始化的内部类,挪到类里面的一个方法里面即可。原先出问题的代码
public class W extends Wifi<String>{@Overridepublic String getNet(){// TODO Auto-generated method stubreturn "WWWW";}}public static void main(String[] args){// TODO Auto-generated method stubW ww = new W();ww.net();ww.ondo();System.out.println(ww.getNet());}修改之后:
public class W extends Wifi<String>{@Overridepublic String getNet(){// TODO Auto-generated method stubreturn "WWWW";}}public void testW(){W ww = new W();ww.net();ww.ondo();System.out.println(ww.getNet());}public static void main(String[] args){// TODO Auto-generated method stubtest5 test5 = new test5();test5.testW();}
相关文章推荐
- Codeforces Round #313 (Div. 2)D. Equivalent Strings(字符串)
- Hibernate的5个核心接口:Session、SessionFactory、Transaction、Query和Configuration
- 论如何是用RTP打包H264数据(发送分包发送分析)
- 黑马程序员——String类常见的操作方法
- Android L中间RecyclerView 、CardView 、Palette使用
- ural 1022 Genealogical Tree
- Android 恢复出厂设置(recovery)
- Javascript中的typeof的用法
- 如何去除打开几个WORD文件在一个窗口
- 构建树并计算算术表达式(为了应付该作业,仅供参考)
- Openssl pkey命令
- 修改主机名后TFS重新映射问题
- poj 2828 Buy Tickets (线段树 单节点 查询位置更新)
- 【LeetCode】238. Product of Array Except Self
- HDU 1258 Sum It Up
- 根据像素画圆
- hdoj.5289 Assignment【单调队列】 2015/07/25
- A计划(bfs)
- 去掉标题栏、信息栏和实现全屏
- sublime常用快捷键