gpt4 book ai didi

java - eclipse 错误:unresolved compilation

转载 作者:行者123 更新时间:2023-11-29 05:49:16 24 4
gpt4 key购买 nike

我有这个代码

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 :

To instantiate an inner class, you must first instantiate the outer class.

语法:

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

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

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

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com