gpt4 book ai didi

java - For-each 未正确迭代

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

我得到这个 for-each 循环,它没有正确迭代对象“CharacterMove”的 ArrayList。我知道它不是空的,因为我在迭代之前尝试打印 size()

这是我的 for-each

for (CharacterMove move : charinfo.getMoves()) {

数组列表

private List<CharacterMove> moveset = new ArrayList<>();

有人吗?

编辑:完整方法如下

public static void writeDataFromChara(CharacterInfo charinfo, String fileTarget, boolean popupFail) {
try {
File file = new File(fileTarget);
PrintStream ps = new PrintStream(file);

ps.print("<INFO>");
ps.println();

System.out.println("Size: " + charinfo.getMoves().size());

//Write the information
for (Entry<String, String> entry : charinfo.tree.getAllDatas().entrySet()) {
ps.print(entry.getKey() + ":" + entry.getValue());
ps.println();
}

//Write the moves, frames and hitboxes
for (CharacterMove move : charinfo.getMoves()) {
System.out.println("Z"); //Never called just like everything else
ps.print(move.name + ":");
ps.println();
for (Pair<CharacterMoveFrame,Integer> frame : move.frames) {
ps.print("frame:"); //Indicate that this is part of a new frame
for (Entry<String, Collider> collider : frame.left.hitboxes.entrySet()) {
ps.print(collider.getValue().x + ",");
ps.println();
ps.print(collider.getValue().y + ",");
ps.println();
ps.print(collider.getValue().w + ",");
ps.println();
ps.print(collider.getValue().h);
ps.println();
}
}
}
ps.close();
} catch (IOException e0) {
if (popupFail) {
JOptionPane.showMessageDialog(new JPanel(), "An error happened while writing the data", "Error", 1);
}
}
}

最佳答案

检查这一行;

   System.out.println("Size: " + charinfo.getMoves().size());

如果大小为“0”,则第一个 for-each 循环不起作用。

关于java - For-each 未正确迭代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12169965/

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