java - Android build crashes when looping through an 2D array - libGDX -
i point.
i'm working on little game, using libgdx library , have following problem.
everytime i'm trying execute loop:
for (int row = 0; row < currentmapheighttiles; row++) { (int col = 0; col < 9; col++) { if (currentmap[row][col] == 4 && (currentmapheight - position.y) > row * 40 && (currentmapheight - position.y) < (row+1) * 40 && position.x > col * 40 && position.x < (col+1) * 40) { gdx.app.log("wall collision", "found"); collides = true; } else if (currentmap[row][col] == 3 && (currentmapheight - position.y) > row * 40 && (currentmapheight - position.y) < (row+1) * 40 && position.x > col * 40 && position.x < (col+1) * 40) { gdx.app.log("gate collision", "found"); collides = true; } } } my android build crashes. works charm on desktop version, compiles on android, i'm executing it, phone says "my app stopped working".
simplified version of doesn't work well:
for (int row = 0; row < currentmapheighttiles; row++) { (int col = 0; col < 9; col++) { if (currentmap[row][col] == 4) { } else if (currentmap[row][col] == 3) { } } } and 1 doesn't anything, iterates through array.
2d array created method:
public int[][] getmap() throws exception { string line; scanner scanner = new scanner(new file("data/level_one.txt")); (int row = 0; row < maph; row++) { line = scanner.nextline(); string[] rowa = line.split(" "); (int col = 0; col < 9; col++) { levelmap[row][col] = integer.parseint(rowa[col]); } } return levelmap; } logs:
06-03 15:34:42.195 1293-1293/com.mestru.game.android d/dalvikvm﹕ trying load lib /data/app-lib/com.mestru.game.android-1/libgdx.so 0xb1db73c8 06-03 15:34:42.265 1293-1293/com.mestru.game.android d/dalvikvm﹕ added shared lib /data/app-lib/com.mestru.game.android-1/libgdx.so 0xb1db73c8 06-03 15:34:42.265 1293-1293/com.mestru.game.android d/dalvikvm﹕ no jni_onload found in /data/app-lib/com.mestru.game.android-1/libgdx.so 0xb1db73c8, skipping init 06-03 15:34:42.425 1293-1293/com.mestru.game.android d/﹕ hostconnection::get() new host connection established 0xb8466920, tid 1293 06-03 15:34:42.965 1293-1293/com.mestru.game.android i/androidinput﹕ sensor listener setup 06-03 15:34:43.215 1293-1293/com.mestru.game.android w/egl_emulation﹕ eglsurfaceattrib not implemented 06-03 15:34:43.235 1293-1293/com.mestru.game.android d/openglrenderer﹕ enabling debug mode 0 06-03 15:34:43.385 1293-1306/com.mestru.game.android d/﹕ hostconnection::get() new host connection established 0xb85aba30, tid 1306 06-03 15:34:43.425 1293-1306/com.mestru.game.android w/gl2jniview﹕ creating opengl es 2.0 context 06-03 15:34:43.545 1293-1306/com.mestru.game.android d/dalvikvm﹕ trying load lib /data/app-lib/com.mestru.game.android-1/libgdx.so 0xb1db73c8 06-03 15:34:43.545 1293-1306/com.mestru.game.android d/dalvikvm﹕ shared lib '/data/app-lib/com.mestru.game.android-1/libgdx.so' loaded in same cl 0xb1db73c8 06-03 15:34:43.555 1293-1306/com.mestru.game.android i/gl2﹕ initialized 2 06-03 15:34:43.565 1293-1306/com.mestru.game.android i/androidgraphics﹕ ogl renderer: android emulator opengl es translator (amd radeon r9 200 series) 06-03 15:34:43.565 1293-1306/com.mestru.game.android i/androidgraphics﹕ ogl vendor: google (ati technologies inc.) 06-03 15:34:43.575 1293-1306/com.mestru.game.android i/androidgraphics﹕ ogl version: opengl es 2.0 (4.4.13283 compatibility profile context 14.501.1003.0) 06-03 15:34:43.625 1293-1306/com.mestru.game.android i/androidgraphics﹕ ogl extensions: gl_ext_debug_marker gl_oes_egl_image gl_oes_egl_image_external gl_oes_depth24 gl_oes_depth32 gl_oes_element_index_uint gl_oes_texture_float gl_oes_texture_float_linear gl_oes_compressed_paletted_texture gl_oes_compressed_etc1_rgb8_texture gl_oes_depth_texture gl_oes_texture_half_float gl_oes_texture_half_float_linear gl_oes_packed_depth_stencil gl_oes_vertex_half_float gl_oes_texture_npot gl_oes_rgb8_rgba8 06-03 15:34:43.625 1293-1306/com.mestru.game.android e/egl_emulation﹕ [getattribvalue] bad attribute idx 06-03 15:34:43.625 1293-1306/com.mestru.game.android e/egl_emulation﹕ tid 1306: eglgetconfigattrib(605): error 0x3004 (egl_bad_attribute) 06-03 15:34:43.635 1293-1306/com.mestru.game.android e/egl_emulation﹕ [getattribvalue] bad attribute idx 06-03 15:34:43.635 1293-1306/com.mestru.game.android e/egl_emulation﹕ tid 1306: eglgetconfigattrib(605): error 0x3004 (egl_bad_attribute) 06-03 15:34:43.635 1293-1306/com.mestru.game.android i/androidgraphics﹕ framebuffer: (5, 6, 5, 0) 06-03 15:34:43.635 1293-1306/com.mestru.game.android i/androidgraphics﹕ depthbuffer: (16) 06-03 15:34:43.635 1293-1306/com.mestru.game.android i/androidgraphics﹕ stencilbuffer: (0) 06-03 15:34:43.635 1293-1306/com.mestru.game.android i/androidgraphics﹕ samples: (0) 06-03 15:34:43.635 1293-1306/com.mestru.game.android i/androidgraphics﹕ coverage sampling: (false) 06-03 15:34:43.675 1293-1306/com.mestru.game.android i/androidgraphics﹕ managed meshes/app: { } 06-03 15:34:43.675 1293-1306/com.mestru.game.android i/androidgraphics﹕ managed textures/app: { } 06-03 15:34:43.685 1293-1306/com.mestru.game.android i/androidgraphics﹕ managed cubemap/app: { } 06-03 15:34:43.685 1293-1306/com.mestru.game.android i/androidgraphics﹕ managed shaders/app: { } 06-03 15:34:43.685 1293-1306/com.mestru.game.android i/androidgraphics﹕ managed buffers/app: { } 06-03 15:34:43.695 1293-1306/com.mestru.game.android i/mathsgame﹕ created 06-03 15:34:44.185 1293-1306/com.mestru.game.android w/system.err﹕ java.io.filenotfoundexception: /data/level_one.txt: open failed: enoent (no such file or directory) 06-03 15:34:44.185 1293-1306/com.mestru.game.android w/system.err﹕ @ libcore.io.iobridge.open(iobridge.java:409) 06-03 15:34:44.285 1293-1306/com.mestru.game.android w/system.err﹕ @ java.io.fileinputstream.<init>(fileinputstream.java:78) 06-03 15:34:44.285 1293-1306/com.mestru.game.android w/system.err﹕ @ java.util.scanner.<init>(scanner.java:158) 06-03 15:34:44.305 1293-1306/com.mestru.game.android w/system.err﹕ @ java.util.scanner.<init>(scanner.java:138) 06-03 15:34:44.305 1293-1306/com.mestru.game.android w/system.err﹕ @ com.mestru.screens.levels.level_one.getmap(level_one.java:24) 06-03 15:34:44.315 1293-1306/com.mestru.game.android w/system.err﹕ @ com.mestru.gameworld.gameworld.initlevels(gameworld.java:45) 06-03 15:34:44.315 1293-1306/com.mestru.game.android w/system.err﹕ @ com.mestru.gameworld.gameworld.<init>(gameworld.java:35) 06-03 15:34:44.315 1293-1306/com.mestru.game.android w/system.err﹕ @ com.mestru.screens.gamescreen.<init>(gamescreen.java:19) 06-03 15:34:44.425 1293-1306/com.mestru.game.android w/system.err﹕ @ com.mestru.game.mathsgame.create(mathsgame.java:14) 06-03 15:34:44.425 1293-1306/com.mestru.game.android w/system.err﹕ @ com.badlogic.gdx.backends.android.androidgraphics.onsurfacechanged(androidgraphics.java:241) 06-03 15:34:44.435 1293-1306/com.mestru.game.android w/system.err﹕ @ android.opengl.glsurfaceview$glthread.guardedrun(glsurfaceview.java:1512) 06-03 15:34:44.435 1293-1306/com.mestru.game.android w/system.err﹕ @ android.opengl.glsurfaceview$glthread.run(glsurfaceview.java:1240) 06-03 15:34:44.435 1293-1306/com.mestru.game.android w/system.err﹕ caused by: libcore.io.errnoexception: open failed: enoent (no such file or directory) 06-03 15:34:44.435 1293-1306/com.mestru.game.android w/system.err﹕ @ libcore.io.posix.open(native method) 06-03 15:34:44.435 1293-1306/com.mestru.game.android w/system.err﹕ @ libcore.io.blockguardos.open(blockguardos.java:110) 06-03 15:34:44.435 1293-1306/com.mestru.game.android w/system.err﹕ @ libcore.io.iobridge.open(iobridge.java:393) 06-03 15:34:44.435 1293-1306/com.mestru.game.android w/system.err﹕ ... 11 more 06-03 15:34:44.885 1293-1306/com.mestru.game.android d/dalvikvm﹕ gc_for_alloc freed 232k, 9% free 3153k/3452k, paused 50ms, total 53ms 06-03 15:34:46.105 1293-1306/com.mestru.game.android d/dalvikvm﹕ gc_for_alloc freed 393k, 13% free 3253k/3716k, paused 41ms, total 42ms 06-03 15:34:46.525 1293-1306/com.mestru.game.android d/dalvikvm﹕ gc_for_alloc freed 67k, 11% free 3402k/3796k, paused 40ms, total 40ms 06-03 15:34:46.565 1293-1306/com.mestru.game.android i/gamescreen﹕ show called 06-03 15:34:46.565 1293-1306/com.mestru.game.android i/gamescreen﹕ resize called 06-03 15:34:46.565 1293-1306/com.mestru.game.android i/gamescreen﹕ resize called 06-03 15:34:54.915 1293-1306/com.mestru.game.android w/dalvikvm﹕ threadid=11: thread exiting uncaught exception (group=0xb1ad9ba8) 06-03 15:34:54.925 1293-1306/com.mestru.game.android e/androidruntime﹕ fatal exception: glthread 93 process: com.mestru.game.android, pid: 1293 java.lang.nullpointerexception @ com.mestru.objects.player.checkcollision(player.java:143) @ com.mestru.objects.player.update(player.java:56) @ com.mestru.gameworld.gameworld.update_one(gameworld.java:83) @ com.mestru.gameworld.gameworld.update(gameworld.java:71) @ com.mestru.screens.gamescreen.render(gamescreen.java:32) @ com.badlogic.gdx.game.render(game.java:46) @ com.badlogic.gdx.backends.android.androidgraphics.ondrawframe(androidgraphics.java:422) @ android.opengl.glsurfaceview$glthread.guardedrun(glsurfaceview.java:1523) @ android.opengl.glsurfaceview$glthread.run(glsurfaceview.java:1240) 06-03 15:34:58.145 1293-1306/com.mestru.game.android i/process﹕ sending signal. pid: 1293 sig: 9 so yeah, conclusing - everytime go through array, android build crashes. when i'm trying use try/catch, doesn't check collision @ all. use <3
edit. still can't work :<
edit2. luckily managed make work. i've replaced
scanner scanner = new scanner(new file("data/level_one.txt")); with
filehandle file = gdx.files.internal("data/level_one.txt"); scanner scanner = new scanner(file.readstring()); and works charm :)
in line of code thinks 1 problem->
public int[][] getmap() throws exception { string line; scanner scanner = new scanner(new file("data/level_one.txt")); (int row = 0; row < maph; row++) { line = scanner.nextline(); string[] rowa = line.split(" "); (int col = 0; col < 9; col++) { levelmap[row][col] = integer.parseint(rowa[col]); } } return levelmap; } .
scanner scanner = new scanner(new file("data/level_one.txt"));
example:
scanner scanner = new scanner(gdx.files.internal("data/level_one.txt").file()); read , implement in code:
https://github.com/libgdx/libgdx/wiki/file-handling#reading-from-a-file
https://github.com/libgdx/libgdx/wiki/file-handling#obtaining-filehandles
maybe affecting in code, hope help, if not notify me , delete response
Comments
Post a Comment