奇怪的空指针异常 [英] Strange null pointer exception
问题描述
我有以下全局数组...
I've got the following global array...
public static float camObjCoord[] = new float[8000];
我有一种方法可以将值输入到它的索引中,我正在像这样发送它们...
I've got a method feeding values into its indexes I'm sending them like so...
layers.addcube(-6, -2, -6, -2);
i 是一个类变量,声明为..
i is a class variable declared as..
int i = 0;
并且层被声明为...
GLLayer layers = new GLLayer(this);
但是当我这样做时,我在...处收到 NullPointerException 异常
But when I do I get a NullPointerException at....
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.
有谁知道为什么它给我一个空指针?还有更多代码,但我认为只提供相关内容就足够了.
Does anyone have any idea why it's giving me a null pointer? There is more code but I thought it'd be sufficent to give you only what's relevant.
谢谢
推荐答案
试试改成这样:
public final static float camObjCoord[] = new float[8000];
正如我假设您在这里更新 camObjCoord 并将其设置为 null.否则,我看不到您如何在该行中获得 NullPointerException.
As I assume you somwehere update camObjCoord and set it to null. Otherwise I do not see how you could get a NullPointerException in that line.
这篇关于奇怪的空指针异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!