Sandeep Tiwari
Sandeep Tiwari

Reputation: 2072

Why come NullPointerException?

I am developing openGL live wallpaper using Robert Green GLWallpaperService jar file. there is an exception come after running the code no wallpaper do ant draw task on Screen----

02-16 11:09:31.941: E/AndroidRuntime(6286): FATAL EXCEPTION: GLThread 9
02-16 11:09:31.941: E/AndroidRuntime(6286): java.lang.NullPointerException
02-16 11:09:31.941: E/AndroidRuntime(6286): at com.inoxmobile.waterlwp.WaterLiveWallpaperRenderer.onDrawFrame(WaterLiveWallpaperRenderer.java:152)
02-16 11:09:31.941: E/AndroidRuntime(6286): at    
com.inoxmobile.waterlwp.GLThread.guardedRun(GLWallpaperService.java:683)    
02-16 11:09:31.941: E/AndroidRuntime(6286):at com.inoxmobile.waterlwp.GLThread.run(GLWallpaperService.java:541)

I am using this code for that-----

public void onDrawFrame(GL10 gl)
  {

    if (gl == null)
        return;

    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);    

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    if (usebg) {
        gl.glDepthMask(false);
        mBackground.draw(gl);//Exception come Here..........
        gl.glDepthMask(true);
    }

    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();    

    //if (usebg){
        //mBackground.Init(gl);
        //mBackground.setDims(mWidth, mHeight);
    //}
}

Upvotes: 0

Views: 696

Answers (1)

user8709
user8709

Reputation: 1352

Are you certain you have initialized mBackground in onCreate() or the constructor of this class? Remember, if you only have a member declaration,

private Background mBackground; 

this is equivalent to

private Background mBackground = null;

Upvotes: 1

Related Questions