一個NullPointerException
被拋出這個代碼的33行:NullPointerException異常拋出無緣無故
|31| @Override
|32| public float[] getVertices() {
|33| return new float[] {
|34| center.x - radius, center.y - radius, 0, 1,
|35| center.x + radius, center.y + radius, 1, 0,
|36| center.x - radius, center.y + radius, 0, 0,
|37| center.x - radius, center.y - radius, 0, 1,
|38| center.x + radius, center.y - radius, 1, 1,
|39| center.x + radius, center.y + radius, 1, 0
|40| };
|41| }
我知道有很多原因NullPointerExceptions
被拋出,但我沒有看到任何東西線路導致異常。
center.x
,center.y
和radius
以前都在代碼中定義過,所以它們不爲空。我做了Log.v(TAG, "center.x: " + center.x + ", center.y: " + center.y + ", radius: " + radius)
,只是爲了檢查,如果他們被定義,這是結果:center.x: 0, center.y: 0, radius, 1
這裏是堆棧跟蹤:
java.lang.NullPointerException
at com.vcapra1.breakoutgame.objects.Ball.getVertices(Ball.java:33)
at com.vcapra1.breakoutgame.objects.TextureObject.<init>(TextureObject.java:17)
at com.vcapra1.breakoutgame.objects.Ball.<init>(Ball.java:16)
at com.vcapra1.breakoutgame.BreakoutRenderer.onSurfaceCreated(BreakoutRenderer.java:66)
at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1509)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1248)
也許中心爲空? – Blackbelt 2014-09-26 19:56:17
請構建一個最小的測試用例。 – 2014-09-26 19:57:21
你在哪裏登錄? - 在創建'float []'之前嘗試記錄。 – igr 2014-09-26 19:57:26