我得到了下面的全局数组...
public static float camObjCoord[] = new float[8000];我有一个方法将值输入到它的索引中,我像这样发送它们...
layers.addcube(-6, -2, -6, -2);I是一个声明为..的类变量。
int i = 0;层被声明为...
GLLayer layers = new GLLayer(this);但是当我这样做的时候,我会在....得到一个NullPointerException。
public void addcube(float highx, float lowx, float highz, float lowz){
//Constructing new cube...
cubes++;
float highy = 4.5f;
float lowy = 2.5f;
//FRONT
Global.camObjCoord[i] = highx; //null pointer here.有人知道为什么它会给我一个空指针吗?有更多的代码,但我认为只给你相关的代码就足够了。
谢谢
发布于 2010-07-12 21:24:53
尝试将其更改为以下内容:
public final static float camObjCoord[] = new float[8000];我假设你需要更新camObjCoord并将其设置为null。否则,我看不出你怎么能在这行得到一个NullPointerException。
发布于 2010-07-12 21:22:50
您确定这是NullPointerException而不是ArrayIndexOutOfBoundsException吗?如果为start != 0,则i为数组的长度。然而,数组索引从0运行到length - 1 -因此您需要i = Global.camObjCoord.length - 1;在您声明抛出异常的行中获取有效的索引。
发布于 2010-07-12 21:23:03
最高数组索引应为array.length - 1。所以
if(start != 0){
i = Global.camObjCoord.length - 1;
} https://stackoverflow.com/questions/3228891
复制相似问题