Java出现No enclosing instance of type E is accessible. Must qualify the allocation with an enclosing

来源:互联网 发布:3d房屋设计软件 编辑:程序博客网 时间:2024/05/17 21:41

        http://blog.csdn.net/sunny2038/article/details/6926079

        这是不改动其他部分的解决方法。但是当我重新建一个java文件,再把那个类剪切到新建的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).         

        他的意思就是:没有任何类型 TestThread 的外层实例可访问。必须用类型 TestThread 的外层实例(例如,x.new A(),其中 x 是 TestThread 的实例)来限定分配。

    例如:

public class CarTest {  public class Car{    String engine;    String Wheel;    public void run(){      System.out.println("汽车在奔跑");    }  }  /**   * @param args   */  public static void main(String[] args) {    // TODO Auto-generated method stub    //CarTest obj = new CarTest();        //Car car = obj.new Car();    //或者   <span style="background-color: rgb(255, 204, 0);"> Car car = new CarTest().new Car();</span>              car.engine = "奇瑞";          car.run();  }} 运行测试:汽车在奔跑

    问题完美解决。

0 0