在编译一个例子时,结果编译时出现:

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

(W为文件名)

根据提示,没有可访问的内部类W的实例,必须分配一个合适的内部类W的实例(如x.new A(),x必须是W的实例。)

但是我已经实例化了这个类,为什么还不行呢。

经过查询相关资料。原来我写的内部类是动态的,也就是开头以public class开头,或者默认的为动态的。而主程序是public static class main。在Java中,类中的静态方法不能直接调用动态方法。只有将某个内部类修饰为静态类,然后才能够在静态类中调用该类的成员变量与成员方法。所以解决办法是将public class改为public static class.

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的更多相关文章

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

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

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

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

  5. 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).

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

  6. 【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. ...

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

  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. VC的话有必要认真听,但却不用急着照办

    本文来自著名风险投资人 Fred Wilson 的博客 AVC,他在 2016 年 8 月 23 日的这篇文章<Understanding VCs>里用简单的语言揭秘了 VC(风险投资人) ...

  2. js深入研究之初始化验证

    <script type="text/javascript"> var Book = function(isbn, title, author) { if(!this. ...

  3. 读书笔记:java特种兵(上)

    ----看着样章,感觉还不错,就买下来了,书先不论好坏,悟到了一个道理,东西没有好与坏,只有适不适合. 第一章:想了解编译器是如何优化程序的,当年的编译原理没有学好啊

  4. cf437C The Child and Toy

    C. The Child and Toy time limit per test 1 second memory limit per test 256 megabytes input standard ...

  5. myeclipse实现Servlet实例(3) 通过继承HttpServlet接口实现

    (1) 在软件公司 90%都是通过该方法开发. //在HttpServlet 中,设计者对post 提交和 get提交分别处理   //回忆 <form action="提交给?&qu ...

  6. C# 二分查询

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  7. python高级编程:有用的设计模式3

    # -*- coding: utf-8 -*-__author__ = 'Administrator'#python高级编程:有用的设计模式#访问者:有助于将算法从数据结构中分离出来"&qu ...

  8. Web Service-- 使用 JDK 发布 WS

    Web Service,即“Web 服务”,简写为 WS,从字面上理解,它其实就是“基于 Web 的服务”.而服务却是双方的,有服务需求方,就有服务提供方.服务提供方对外发布服务,服务需求方调用服务提 ...

  9. (转)iOS7界面设计规范(9) - UI基础 - 动画

    傍晚下了场大雨,现在坐在屋里也真是很风凉,听着Everlong突然觉得好像去年秋天的气息.每个季节都有各自的气息,每一年也是,如果你留意,便会感觉到.话说这几天,外面的猫猫狗狗们可以补些水来喝了,这也 ...

  10. 为iPhone 6设计自适应布局

    Apple从iOS 6加入了Auto Layout后开始就比较委婉的开始鼓励.建议开发者使用自适应布局,但是到目前为止,我感觉大多数开发者一直在回避这个问题,不管是不是由于历史原因造成的,至少他们在心 ...