java - 未调用 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"});
}
}
推荐阅读
- scala - Scala、Spark-shell、Groupby 失败
- python - 如何在 python 中处理复杂的用户输入?
- javascript - Three.js 将框添加到场景中不适用于 iOS
- php - 在 symfony 中找不到 .env 文件
- android - Jumio 的 NetverifySDK 未预选提供的国家/地区
- actionscript-3 - 在 AS3 中单击对象
- amazon-web-services - 使用 getRecords 从 kinesis 数据流中获取时缺少记录
- java - 询问spring4.3.11 + mybatis 3.2 8
- mysql - Database Model - Tournaments for eSports
- mongodb - 如何在集合mongodb的同一对象中将一个数据字段设置为另一个日期字段