Reputation: 55
I developing opengl android app using opengl ES 2.0. My app crashes and write in log this:
07-28 22:55:29.460 13407-13420/?
E/AndroidRuntime: FATAL EXCEPTION: GLThread 1293 java.lang.NullPointerException at com.jayway.gles20.GLES20Renderer.draw_worlddate(GLES20Renderer.java:521) at com.jayway.gles20.GLES20Renderer.onDrawFrame(GLES20Renderer.java:503) at com.jayway.gles20.GLRenderer.onDrawFrame(GLRenderer.java:87) at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1516) at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
Error in this function:
public void draw_worlddate(String wtype){
Map<String,float[][][]> wdw=worlddate.world;
float[][][] ww;
ww = wdw.get(wtype);
float[][] ww2;
float[] ww3;
for (int i=0;i<ww.length;i++){//this is line 521
ww2=ww[i];
Matrix.setIdentityM(mModelMatrix, 0);
for(Integer i2=0;i2<ww2.length;i2++){
ww3=ww2[i2];
switch (i2){
case 0:
Matrix.translateM(mModelMatrix,0,ww3[0],ww3[1],ww3[2]);
break;
case 1:
Matrix.rotateM(mModelMatrix,0,0.0f,ww3[0],ww3[1],ww3[2]);
break;
case 2:
Matrix.scaleM(mModelMatrix,0,ww3[0],ww3[1],ww3[2]);
break;
}
}
drawTriangle(mTriangle1Vertices);
}
}
The parsing array int the Map:
{
{
{
1.0f,
1.0f,
1.0f
},
{
1.0f,
1.0f,
1.0f
},
{
1.0f,
1.0f,
1.0f
}
}
}
How to fix this?
Upvotes: 1
Views: 1030
Reputation: 159874
Check that the Map
wdw
contains a value for the associated key before attempting to determine the length of the retrieved array
if (wdw.containsKey(wtype)) {
ww = wdw.get(wtype);
...
for (int i=0; i <ww.length;i++){
...
}
}
Upvotes: 1