java编译错误No enclosing instance of type TestFrame is accessible. Must qualify the allocation with an enclosing instance of type TestFrame (e.g. x.new A(

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

  这是因为AA是一个动态的内部类,创建这样的对象必须有实例与之对应,程序是在静态方法中直接调用动态内部类会报这样错误。   这样的错误好比类中的静态方法不能直接调用动态方法。可以把该内部类声明为static。或者不要在静态方法中调用

那么为啥非静态方法不能调用动态方法呢,从面向对象的角度来说,动态方法与对象是联系密切的,比如发动是一个方法,它与汽车这个对象是关联的,所以只有new了汽车这个对象才能执行汽车.发动。

原文地址:https://www.cnblogs.com/youxin/p/2461059.html