2013-08-24 105 views
-1

當我嘗試調試這個時,我得到了一個nullpointerexception。 我只是不明白,一定不能正確初始化,但我看不到......謝謝!Render上的NullPointerException

@Override 
public void create() 
{  
    Texture.setEnforcePotImages(false); 
    camera = new OrthographicCamera(VIRTUAL_WIDTH, VIRTUAL_HEIGHT); 
    camera.setToOrtho(true,VIRTUAL_WIDTH,VIRTUAL_HEIGHT); 
    batch = new SpriteBatch(); 

    labyrinthe = new Labyrinthe(2, VIRTUAL_WIDTH); 
    labyrinthe.generer(); 
    joueur = labyrinthe.getJoueur(); 
} 

@Override 
public void dispose() 
{ 
    batch.dispose(); 
} 

@Override 
public void render() 
{    
    camera.position.set(joueur.getX(), joueur.getY(), 0); 
    camera.update(); 
    camera.apply(Gdx.gl10); 

    Gdx.gl.glViewport((int) viewport.x, (int) viewport.y, (int) viewport.width, (int) viewport.height); 
    Gdx.gl.glClearColor(1, 1, 1, 1); 
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); 

    batch.setProjectionMatrix(camera.combined); 
    batch.begin(); 
    dessinerLabyrinthe(); 
    dessinerJoueur(); 
    batch.end(); // Exception on this line 
} 

編輯:這裏是例外:

08-24 09:22:02.413: W/dalvikvm(224): threadid=21: thread exiting with uncaught exception (group=0x4001b188) 
08-24 09:22:02.413: E/AndroidRuntime(224): Uncaught handler: thread GLThread exiting due to uncaught exception 
08-24 09:22:02.480: E/AndroidRuntime(224): java.lang.NullPointerException 
08-24 09:22:02.480: E/AndroidRuntime(224): at com.badlogic.gdx.graphics.g2d.SpriteBatch.renderMesh(SpriteBatch.java:1042) 
08-24 09:22:02.480: E/AndroidRuntime(224): at com.badlogic.gdx.graphics.g2d.SpriteBatch.end(SpriteBatch.java:269) 
08-24 09:22:02.480: E/AndroidRuntime(224): at com.me.crazymazes.CrazyMazes.render(CrazyMazes.java:60) 
08-24 09:22:02.480: E/AndroidRuntime(224): at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:452) 
08-24 09:22:02.480: E/AndroidRuntime(224): at com.badlogic.gdx.backends.android.surfaceview.GLSurfaceViewCupcake$GLThread.guardedRun(GLSurfaceViewCupcake.java:713) 
08-24 09:22:02.480: E/AndroidRuntime(224): at com.badlogic.gdx.backends.android.surfaceview.GLSurfaceViewCupcake$GLThread.run(GLSurfaceViewCupcake.java:646) 

EDIT2:沒關係我忘了打電話產生的紋理功能....謝謝反正

+0

請分享異常跟蹤並提及您所在的行gettng NPE –

+0

完成了,告訴我是否需要更多代碼 – user2090805

回答

-3

在公共無效創建( )add this,

renderer.render(); 
+0

我沒有任何渲染器 – user2090805

相關問題