簡體   English   中英

未調用 Java 的靜態方法

[英]Static method not being called 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 給了我一個錯誤。 請幫助並提前感謝您。

我們需要修復兩個錯誤;

    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"});
}
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM