No enclosing instance of type Demo is accessible. Must qualify the allocation with an enclosing instance of type Demo (e.g. x.new A() where 
x is an instance of Demo).

在练习一Demo时,遇到上面的编译时错误

原因:main是Test类的static方法,按照常理它只能访问Test类中static资源,而class A是非static所以报错了。

解决方法一:给class F添加static属性。

解决方法二: 没有必要把F放在Demo中做内部类,将它移到Demo外部地方定义。

No enclosing instance of type Demo is accessible. Must qualify the allocation with an enclosing instance of type Demo (e.g. x.new A() where x is an instance of Demo).的更多相关文章

  1. No enclosing instance of type test is accessible. Must qualify the allocation with an enclosing inst

    今日遇到一个报错如下: No enclosing instance of type test is accessible. Must qualify the allocation with an en ...

  2. 【转】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 ...

  3. 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   ...

  4. No enclosing instance of type test8 is accessible. Must qualify the allocation with an enclosing instance of type test8 (e.g. x.new A() where x is an

    在编译一个例子时,结果编译时出现: No enclosing instance of type test8 is accessible. Must qualify the allocation wit ...

  5. No enclosing instance of type Outer is accessible. Must qualify the allocation with an enclosing instance of type Outer (e.g. x.new A() where x is an instance of Outer)

    之前看内部类的时候没发现这个问题,今天写代码的时候遇到,写个最简单的例子: 下面这一段代码 红色的部分就是编译报错: No enclosing instance of type Outer is ac ...

  6. No enclosing instance of type Test is accessible. Must qualify the allocation with an enclosing instance of type Test (e.g. x.new A() where x is an instance of Test).

    Java编写代码过程中遇到了一个问题,main方法中创建内部类的实例时,编译阶段出现错误,查看错误描述: No enclosing instance of type Test is accessibl ...

  7. 【eclipse】No enclosing instance of type A is accessible. Must qualify the allocation with an enclosing instance of type A

    用 eclipse 写 Java 代码时出现了这个问题,详细如下: No enclosing instance of type TestParsingLinkedList is accessible. ...

  8. No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing

    在Java中,类中的静态方法不能直接调用动态方法.只有将某个内部类修饰为静态类,然后才能够在静态类中调用该类的成员变量与成员方法.所以在不做其他变动的情况下,最简单的解决办法是将public clas ...

  9. Java中报错No enclosing instance of type caiquan is accessible. Must qualify the allocation with an enclosing instance of type caiquan (e.g. x.new A() where x is an instance of caiquan).

    package test;import java.util.Scanner;import java.util.Random;public class caiquan { public static v ...

随机推荐

  1. 一个应用 可以有多个application

    韩梦飞沙 yue31313 韩亚飞 han_meng_fei_sha 313134555@qq.com 一个应用里面怎样才能有2个application 一个AndroidManifest.xml中可 ...

  2. AGC 022 B - GCD Sequence

    题面在这里! 锻炼脑子的小构造题... 一开始被 a[]<=30000 且 序列 gcd = 1所困扰,但是发现这并没有什么,因为我接下来发现了一种总是能构造出 序列和是6的倍数的方案. 首先如 ...

  3. HDU 2255 奔小康赚大钱(KM算法)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=2255 [题目大意] 求最大匹配 [题解] KM模板 [代码] #include <cstdi ...

  4. 【二分图匹配】BZOJ1562-[NOI2009] 变换序列

    [题目大意] 对于0,1,…,N-1的N个整数,给定一个距离序列D0,D1,…,DN-1,定义一个变换序列T0,T1,…,TN-1使得每个i,Ti的环上距离等于Di.一个合法的变换序列应是0,1,…, ...

  5. 邮件发送javamail

    写在前面: 最近要将dms系统原始发邮件的功能(调用的webservice)改变成使用smtp服务来发送邮件(使用javamail来发送),这里简单记录下,方便日后有用到,直接拿来用即可. 首先导入需 ...

  6. 141.最小m 段和问题--划分性DP(特殊数据)

    3278 最小m 段和问题  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description 给定 n 个整数(不一定是正整 ...

  7. php读取超大文件fseek

    function readMaxFile($fp , $start = 0) { $tag = "\n"; $i = 0; $content = ''; while($i < ...

  8. PHP 自定义字符串中的变量名解析

    PHP 自定义字符串中的变量名解析   这样一个需求:页面的 title 可以在后台自定义,自定义内容中可能包含变量,变量用 {$var} 表示, 其中 $var 为变量名 将 title 字段存入数 ...

  9. [典型漏洞分享]一个典型的XSS盲打漏洞可导致全网用户cookie被盗取

    偶平时在做安全测试时,一般是以发现问题为主,点到为止,但做安全的同学可能也遇到过这样的问题,当你尝试向开发的同学描述一个漏洞危害怎么怎么样的时候,双方经常会有一种鸡同鸭讲的感觉,甚至他们觉得我们在夸大 ...

  10. 【web 回车】web项目 注册或登录页面 回车登录无效,解决方案

    解决方案: /** * 登陆按钮的点击事件 */ $("#loginID").click(function(){ var username = $("#u"). ...