Search code examples
javastatic-methods

Static method not being called Java


Since the main method is static, it should be able to be called statically. Therefore, I use:

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

as the static-main code, then call using:

import prototype.server.main.Runtime;

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

to call the static method, but Eclipse is giving me an error. Please help and thank you in advance.


Solution

  • There are two bugs we need to fix;

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