我有这个代码

public class watermark {

    public static void main(String[] args) {
        wmmain m = new wmmain();
        m.setSize(800, 500);
        m.setVisible(true);
    }

    class wmmain extends JFrame /* MAIN WINDOW */
    {
        JMenuBar jmb;
        // ......
    }
}


它在命令提示符下工作正常,但是当我尝试在Eclipse中运行代码时,出现以下错误:

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

at watermark.main(watermark.java:20)


我该怎么办??

最佳答案

Documentation


  要实例化内部类,必须首先实例化外部类
  类。


句法:

OuterClass.InnerClass innerObject = outerObject.new InnerClass();


您需要外部类实例来创建内部类的实例。

wmmain m=new WaterMark().new wmmain();

关于java - eclipse中的错误: Unresolved 编译,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14605355/

10-10 14:33