2012-06-23 56 views
1

我最近3個月沒有和libgdx一起工作,現在我試圖做一個簡單的遊戲,但是當我導入libgdx jar並在我的手機(Android)上運行應用程序時,它崩潰了。我在網上發現ADT版本處理所有的庫。所以我把libgdx jar放在libs文件夾中,但我仍然是應用程序崩潰。Libgdx空指針異常

的logcat:

未捕獲的處理程序:螺紋主力退出,由於未捕獲的異常

了java.lang.RuntimeException:無法恢復活動 {com.class.path/com.class.path。爲ExampleActivity}: 顯示java.lang.NullPointerException

在這之後我在安卓類10篇參考文獻(例如:在android.app.ActivityThread.main ......),而且比我有這個:

產生的原因:在com.badlogic.gdx.backends.android.AndroidApplication.onResume顯示java.lang.NullPointerException (AndroidApplication.java:223)

論libgdx源極線223我已經發現:

((AndroidInput)getInput())。registerSensorListeners();

爲ExampleActivity:

公共類爲ExampleActivity擴展AndroidApplication {

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    initialize(new Game(), false); 
} 

}

遊戲: 公共類遊戲實現ApplicationListener {

@Override 
public void create() { 

} 

@Override 
public void dispose() { 
    // TODO Auto-generated method stub 

} 

@Override 
public void pause() { 
    // TODO Auto-generated method stub 

} 

@Override 
public void render() { 
} 

@Override 
public void resize(int arg0, int arg1) { 
    // TODO Auto-generated method stub 

} 

@Override 
public void resume() { 
    // TODO Auto-generated method stub 

} 

}

PS:對不起,我的英文不好

+0

添加logcat的初步認識和代碼 –

+0

你看到多個異常的代碼?如果onCreate成功完成,libGDX會在onResume中失敗。如果onCreate以醜陋的方式失敗,我有時會在onResume中看到錯誤,所以檢查是否還有其他異常被拋出? –

+0

奇怪的是,不確定AndroidInput在這一點上將如何爲空。 –

回答

0

我正巧遇到這個問題了。並利用固定它的基礎上ModelPreiviewApp

private boolean backFaceCulling = true; 
private boolean alphaBlending = false; 
private float alphaTest = -1; 


public void setAlphaBlending(ModelInstance modelInstance, boolean alphaBlendingEnabled){ 
    if(modelInstance != null){ 
     if(alphaBlendingEnabled){ 
      for (Material mat : modelInstance.materials) { 
       mat.set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA)); 
      } 
     }else{ 
      for (Material mat : modelInstance.materials) { 
       mat.remove(BlendingAttribute.Type); 
      } 
     } 
    } 
} 

public void setAlphaTest(ModelInstance modelInstance, float alphaTestValue){ 
    if(modelInstance != null){ 
     if(alphaTestValue>=0){ 
      for (Material mat : modelInstance.materials) { 
       mat.set(new FloatAttribute(FloatAttribute.AlphaTest, alphaTestValue)); 
      } 
     }else{ 
      for (Material mat : modelInstance.materials) { 
       mat.remove(FloatAttribute.AlphaTest); 
      } 
     } 
    } 
} 


public void setBackFaceCulling(ModelInstance modelInstance, boolean backFaceCullinEnabled) { 

    if (modelInstance != null) { 
     if (backFaceCullinEnabled) { 
      for (Material mat : modelInstance.materials) { 
       mat.remove(IntAttribute.CullFace); 
      } 
     } else { 
      for (Material mat : modelInstance.materials) { 
       mat.set(new IntAttribute(IntAttribute.CullFace, 0)); 
      } 
     } 
    } 
} 

public void onModelLoaded(ModelInstance modelInstance) { 
    ... 
    setBackFaceCulling(modelInstance, true); 
    setAlphaBlending(modelInstance, false); 
    setAlphaTest(modelInstance, -1); 
}