java - 奇怪的空指针异常

标签 java nullpointerexception

我有以下全局数组...

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.

有谁知道为什么它给我一个空指针?还有更多的代码,但我认为只给你相关的代码就足够了。

谢谢

最佳答案

尝试将其更改为:

public final static float camObjCoord[] = new float[8000];

正如我假设您在这里更新 camObjCoord 并将其设置为空。否则我看不出您如何在该行中获得 NullPointerException。

关于java - 奇怪的空指针异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3228891/

相关文章:

java - 在 Netbeans 中构建项目时出错

java - Clojure/Swing/Java 中 BufferedImage 和 ImageObserver 的问题

java - 为什么在使用泛型类时不需要指定类型参数?

java - Java TableRowSorter 中的 NullPointerException

android - 为什么 Activity 的构造函数中的 getApplicationContext() 会抛出空指针异常?

java - 在 MouseClicked 中使用 for-each 循环来 getX 和 getY 每个对象

java - 用于获取 include 和 require 指令的正则表达式

java - 如何在 JFrame 中对齐组合面板?

grails - Grails:无法在空对象上调用方法production()

android - NullPointerException imageView.setImageBitmap(位图)