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. Codeforces #447 Div.2 Tutorial

    Problem A:QAQ 给一个字符串,求出可非连续的QAQ序列有多少个. Analysis:比较水的一道题,记录每一个Q的位置,预处理A的个数即可 然而还是fst了,原因是未考虑一个Q都没有的极端 ...

  2. 交换x,y的三种方式

    1 值传递: #include<iostream> using namespace std; int main(){ void change(int ,int); int x=2,y=3; ...

  3. 【MySQL笔记】数据库的查询

    数据库的查询 注:文中 [ ...] 代表该部分可以去掉. 理论基础:对表对象的一组关系运算,即选择(selection).投影(projection)和连接(join) 1.select语句 子语句 ...

  4. JavaScript继承方式

    我的上一篇随笔中写了有关原型继承的,下面介绍几种更加有用的. 借用构造函数 在解决原型中关于引用类型值所带来的问题,开发人员开始使用一种叫做借用构造函数. 基本思想: 在子类型构造函数的内部调用超类型 ...

  5. CentOS 6.9下iptables通过raw表实现日志输出和调试

    说明:iptables调试的最好方式应该是输出日志了.并且iptables有个raw的表,优先级别最好,且调试时针对icmp协议(ping)进行,那么日志输出就是整条链路串起来输出的,非常的清晰. 前 ...

  6. rman catalog配置简要笔记

    服务端配置: SQL> create tablespace tbs_rman datafile 'H:\oradata\test\tbs_rman.dbf' size 20m autoexten ...

  7. MySQL 连接错误Can't connect to MySQL server on (61)

    链接数据库时忽然遇到一个问题.Mac Navicat链接时报错Can’t connect to MySQL server on ‘xx.xx.xx.xx’ (61). PS. win版Navicat ...

  8. nodejs第一个练习:用Node.js建HTTP服务器

    这是官方的一个例子, 在F盘建立一个tinyphp.js文件,内容: var http = require('http'); http.createServer(function (req, res) ...

  9. IngressController的session stick问题

    周末爬坑,IngressController恢复因为镜像下载和版本问题折腾一下午,晚上终于折腾出个眉目. 首先,在Kubernetes的service中是可以设置Session Affinity的.例 ...

  10. iOS:GCD技术——仅仅执行一次和执行多次 dispatch_once和dispatch_apply

    只执行一次  (多用于单例模式) dispatch_once(dispatch_once_t *predicate, dispatch_block_t block); dispatch_once_t ...