I have an OpenGL application, where I fill a two dimensional int List with data, I also Logging the size every time I put data in it. It works grate, there is 236 row. But after I call the method later in the Log it gives me back that the size is 0.
Here is how the structur looks like:
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());
}
I just can’t understand what is the problem with it, hope someone can help me.
Whole code:
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());
}
}
Ok, Without your code, I can just help this, just declare
as a globally,
and then use dataS through out your class.. and make sure you never initialized dataS again anywhere.
I think you are using different collision class object in Map.java and Main.java file, You are set the value using collision object from Map.java class and checking it size with Main’s collision class.(If am not wrong).