ITPub博客

首页 > 应用开发 > Java > No enclosing instance of type Outer is accessible.

No enclosing instance of type Outer is accessible.

原创 Java 作者:634828354 时间:2017-08-15 15:01:44 0 删除 编辑
No enclosing instance of type Outer is accessible. Must qualify the allocation with an enclosing 
 instance of type Outer (e.g. x.new A() where x is an instance of Outer).

点击(此处)折叠或打开

  1. class Outer {
  2.     class Inner {
  3.     }
  4.     public static void foo() {
  5.         new Inner();
  6.     }
  7.     public void bar() {
  8.         new Inner();
  9.     }
  10.     public static void main(String[] args) {
  11.         new Inner();
  12.     }
  13. }

错误显示:没有可访问的内部类的实例,必须分配一个合适的内部类的实例
错误原因:非静态内部类方法不能被静态内部类调用,必须修饰为静态类才可以
解决方法:将内部类修饰为static



来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/30046312/viewspace-2143543/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-12-01

  • 博文量
    47
  • 访问量
    96785