在我的基于Libgdx的Android游戏中,我正在创建一个Vector2来加载我游戏所需的所有点数。当代码到达
时,我得到NullPointerExceptionpoints[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()) ;
}
i : 0
burstCellGrid.get(i).getColCoordinate() : 841.0
burstCellGrid.get(i).getRowCoordinate() : 1314.0
Exception in thread "LWJGL Application" java.lang.NullPointerException
答案 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()) ;
}
祝你好运