在libGdx中加载Vector2数组时出现问题

时间:2016-01-10 13:43:08

标签: java android vector nullpointerexception libgdx

在我的基于Libgdx的Android游戏中,我正在创建一个Vector2来加载我游戏所需的所有点数。当代码到达

时,我得到NullPointerException
points[i].add(burstCellGrid.get(i).getColCoordinate(),burstCellGrid.get(i).getRowCoordinate()) ;

代码

    points=new Vector2[100];
    for (int i=0;i<burstCellGrid.size();i++){
        System.out.println("i : " + i);
        System.out.println("burstCellGrid.get(i).getColCoordinate() : " + burstCellGrid.get(i).getColCoordinate());
        System.out.println("burstCellGrid.get(i).getRowCoordinate() : " + burstCellGrid.get(i).getRowCoordinate());
        points[i].add(burstCellGrid.get(i).getColCoordinate(),burstCellGrid.get(i).getRowCoordinate()) ;
    }

logcat的

i : 0
burstCellGrid.get(i).getColCoordinate() : 841.0
burstCellGrid.get(i).getRowCoordinate() : 1314.0
Exception in thread "LWJGL Application" java.lang.NullPointerException

1 个答案:

答案 0 :(得分:1)

数组中的向量未实例化,因此在实例化point[i].add之前无法执行point[i] = new Vector2()

for (int i=0;i<burstCellGrid.size();i++){
            System.out.println("i : " + i);
            System.out.println("burstCellGrid.get(i).getColCoordinate() : " + burstCellGrid.get(i).getColCoordinate());
            System.out.println("burstCellGrid.get(i).getRowCoordinate() : " + burstCellGrid.get(i).getRowCoordinate());
            points[i] = new Vector2(burstCellGrid.get(i).getColCoordinate(),burstCellGrid.get(i).getRowCoordinate()) ;
        }
祝你好运