首页 > 解决方案 > 未调用 Java 的静态方法

问题描述

由于main方法是静态的,所以应该可以静态调用。因此,我使用:

package prototype.server.main;

import javax.swing.JFrame;
import prototype.server.main.gui.Swing;

public class Runtime {
    public static void main(String[] argv) {
            Swing swing = new Swing(true, argv[0]);

        @SuppressWarnings("unused")
            JFrame maingui = swing.getGuiFrame();
    }
}

作为静态主代码,然后调用使用:

import prototype.server.main.Runtime;

public class Main {
     Runtime.main(new String{"f"});
}

调用静态方法,但 Eclipse 给我一个错误。请帮助并提前感谢您。

标签: javastatic-methods

解决方案


我们需要修复两个错误;

    import prototype.server.main.Runtime;

public class Main {
// add constructor, or method that you can call another method
// or make this static { ... } block that fits you
public Main() {
//do not forget [] for array
     Runtime.main(new String[]{"f"});
}
}

推荐阅读