一个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