ecplise使用注意

来源:互联网 发布:节目点播安庆网络广播 编辑:程序博客网 时间:2024/06/01 08:09

在ecplise中常常会遇到这样的错误:

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
 No enclosing instance of type test22 is accessible. Must qualify the allocation with an enclosing instance of type test22 (e.g. x.new A() where x is an instance of test22).

原因是主函数为static,而写的类并没有定义为static。

有如下两种解决办法:

1)在自己写的类public class fun{}改为public static class fun{}

2)可是一旦定义了static类就会受到控制,

建议使用第二种方法:先声明外部类,再进行调用

 test22 t = new test22();
  Phone p=t.new Phone("1号");
  p.call();


原创粉丝点击