2013-07-28 69 views
1

我使用opengl ES 2.0開發了opengl android應用程序。我的應用程序崩潰並寫入日誌中:GLThread java.lang.NullPointerException錯誤

07-28 22:55:29.460 13407-13420 /?
E/AndroidRuntime:致命異常:GLThread 1293 顯示java.lang.NullPointerException 在com.jayway.gles20.GLES20Renderer.draw_worlddate(GLES20Renderer.java:521) 在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)

錯誤在此功能:

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); 
    } 
} 

解析陣列INT地圖:

{ 
      { 
        { 
          1.0f, 
          1.0f, 
          1.0f 
        }, 
        { 
          1.0f, 
          1.0f, 
          1.0f 
        }, 
        { 
          1.0f, 
          1.0f, 
          1.0f 
        } 
      } 
    } 

如何解決這一問題?

回答

1

檢查Mapwdw包含試圖確定所檢索的陣列的長度之前,相關聯的鍵的值

if (wdw.containsKey(wtype)) { 
    ww = wdw.get(wtype); 
    ... 
    for (int i=0; i <ww.length;i++){ 
    ... 
    } 
} 
相關問題