gpt4 book ai didi

Java- 'if' 语句被忽略?

转载 作者:行者123 更新时间:2023-11-29 03:07:24 25 4
gpt4 key购买 nike

我的“if”语句被忽略了...
代码有什么问题?

代码:

private ObservableList<String[]> fnlData;
.
.

for (int i = 0; i < fnlData.size(); i++){
if (fnlData.get(i)!=null || fnlData.get(i)[indexC]!=null || fnlData.get(i).length > indexC+1) {
fnlData.get(i)[indexC] = null;
}
}

fnlData.get(0)(=StringArray) 中只有一个元素。
在第一个循环中(当 i=0 时)它应该跳过 'if'
它以某种方式进入并执行 fnlData.get(i)[indexC] = null;
但是因为数组中没有第二个元素,所以出现错误 ArrayIndexOutOfBoundsExceptionInvocationTargetException

enter image description here

最佳答案

如果 fnlData.get(0)!=null 为真,则条件为真,您声称它是。

如果您要求所有条件都为真,请使用 AND,而不是 OR:

if (fnlData.get(i)!=null && fnlData.get(i)[indexC]!=null && fnlData.get(i).length > indexC+1)

关于Java- 'if' 语句被忽略?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31425358/

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