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

    今天编写数据解码方法的时候,写了一个解码模块,自己创建了一个java对象,这个java对象,(我是放在解码模块的类内部的),用来存json数据,运行的时候,eclipse报了一个这个编译错误:

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

(翻译) :

    没有类型解码器的封闭实例是可访问的。必须使用类型解码器的封闭实例来限定分配(例如X是new解码器)(其中X是解码器的实例)。

(原因):

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

     

猜你喜欢

转载自blog.csdn.net/itzhangdaopin/article/details/80677545