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

        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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值