2011-12-05 53 views
1

我有一個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()); 
} 
} 
+0

看我的答案.. – user370305

+0

你試過Main.collision.getWall((X * 2) - 23(Z * 2) - 27);?在Map.java類.. – user370305

+0

我的意見是你的回答下,再次感謝你;) – matthew3r

回答

1

好,W ithout你的代碼,我可以幫助這個,只是聲明

private List<int[]> dataS = new ArrayList<int[]>(); 

作爲全球

,然後通過你的類使用DATAS ..並確保你從未初始化數據單項在任何地方。

我想你在Map.java和Main.java文件中使用了不同的碰撞類對象,你可以使用Map.java類中的碰撞對象來設置它的值,並用Main的碰撞類來檢查它的大小(如果沒有錯誤)。

+0

同樣的,當我填寫它,然後大小回來與236的值,但檢查它的0 – matthew3r

+1

對於這一點,你有把整個代碼.. – user370305

+0

好吧,一會兒,我會刪除那裏不需要的東西。 – matthew3r