1

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

这是我拥有的每个人

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

1 回答 1

0

检查这一行;

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

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

于 2012-08-29T04:30:50.087 回答