我不知道为什么会这样。下面是代码:
import com.lewislovesgames.chopthattree.minecraftservermanager.Main;
public class main {
public static void main(String[] args) {
if (args.length == 0) {
if (args[0] == "--nogui") { // Debugger says this is the line it errors on
System.err.println("NOGUI not made yet");
} else {
System.err.println("[Minecraft Server Manager]: Argument does not exist.");
}
}
System.out.println("[Main]: Running Main Window");
Main main = new Main();
main.setVisible(true);
}
}
在我输入args片段之前,代码确实有效。看起来数组从不为0,因此它会传递到下一行。我正在使用Eclipse进行调试和运行程序。
答案 0 :(得分:1)
您正在检查数组的长度是否为0,并且您尝试访问第0个元素,尽管您知道没有第0个元素。
if (args.length == 0) {
if (args[0] == "--nogui") { // Debugger says this is the line it errors on
System.err.println("NOGUI not made yet");
}
答案 1 :(得分:0)
if (args.length == 0) {
System.err.println("No argument supplied");
}
else {
if (args[0] == "--nogui") { // Debugger says this is the line it errors on
System.err.println("NOGUI not made yet");
//something like this.
}