我有一個OpenGL應用程序,在那裏我的數據填充一個二維INT名單,我也記錄每一次我把數據在它時間的大小後空。它起作用,有236排。但後來的方法後,我打電話的日誌它給我回了大小爲0 這裏是所有制結構的樣子:Android的二維的ArrayList加油吧
Main.java
...
onDrawFrame(GL10 gl) {
if (first == true) {
// the data comes from another method
myList.setData(x, y); // I send the the data for the List
// and also log the List size, which at the end is 236
first = false;
}
myList.check(); // It just Logs the List size, which gives back 0
}
...
List.java
private List<int[]> dataS = new ArrayList<int[]>();
public void setData(int x, int y) {
dataS.add(new int[] { x, y });
Log.i("size", "size: " + dataS.size());
}
public void check() {
Log.i("check", "check: " + dataS.size());
}
我只是不明白什麼是它存在的問題,希望有人能幫助我。
所有代碼:
Main.java
public class Main extends GLSurfaceView implements Renderer {
public void drawGame(GL10 gl) {
if (firstGameFrame == true) {
tMap.setMap();
firstGameFrame = false;
}
collision.check();
}
}
Map.java
public class Map {
public void setMap() {
// map1 is an int map1[][] = {{1,0,1}, {1,1,1}, {0,0,1}}; - of course there are more data in it
for (int z = 0; z < map1.length; z++) {
for (int x = 0; x < map1[z].length; x++) {
if (map1[z][x] == 1) {
collision.getWall((x*2) - 23, (z * 2) - 27);
}
}
}
}
}
Collision.java
public class Collision {
private List<Integer[]> wallCoord = new ArrayList<Integer[]>();
public void getWall(int x, int y) {
wallCoord.add(new Integer[] { x, y });
Log.i("getwall", "getwall " + x + " " + y + " size " + wallCoord.size());
}
public void check() {
Log.i("coords", "size: " + wallCoord.size());
}
}
看我的答案.. – user370305
你試過Main.collision.getWall((X * 2) - 23(Z * 2) - 27);?在Map.java類.. – user370305
我的意見是你的回答下,再次感謝你;) – matthew3r