1

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?

0

1 Answer 1

1

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++){
     ...
   }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.