Android Studio:xxx is not an enclosing class

来源:互联网 发布:sql in 耗时原因 编辑:程序博客网 时间:2024/05/29 11:27

这个问题一般出现在内部类中,若要创建内部类的实例,需要有外部类的实例才行,或者是将内部类设置为静态的,添加 static 关键字

public class A{

      public class B{

      }

}

正常逻辑是 A.B ab = new A.B();

但是就会出现xxx is not an enclosing class,这时候应该写成

A a = new A(); 

A.B ab = a.new B();

或者是class B 改成static class B 这样就可以直接用A.B ab = new A.B();

阅读全文
0 0
原创粉丝点击