gpt4 book ai didi

java - 数组长度永远不会为 0,因此下一行会出现 ArrayOutOfBoundsException

转载 作者:行者123 更新时间:2023-12-01 12:09:42 25 4
gpt4 key购买 nike

我不知道为什么会发生这种情况。代码如下:

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

}
}

在我输入参数片段之前,代码确实有效。看起来数组永远不会为 0,因此它会传递到下一行。我使用 Eclipse 来调试和运行程序。

最佳答案

您正在检查数组的长度是否为 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");
}

关于java - 数组长度永远不会为 0,因此下一行会出现 ArrayOutOfBoundsException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27335813/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com