Java GL.createCapabilities抛出NullPointerException

Java GL.createCapabilities抛出NullPointerException,java,nullpointerexception,lwjgl,Java,Nullpointerexception,Lwjgl,请注意,要用发痒的扳机手指接近选民——这不是“什么是NullPointerException”的重复。在投票结束之前,请阅读整个问题 我使用LWJGL3库制作了一个制作窗口的类。 我试图用这个类在单元测试中创建一个窗口,但它在GL.createCapabilities()方法调用中抛出一个NullPointerException。我将Intellij IDEA用于gradle和Debian 8 这不是NullPointerException的重复,因为我试图找到LWJGL3库引发此异常的原因,

请注意,要用发痒的扳机手指接近选民——这不是“什么是NullPointerException”的重复。在投票结束之前,请阅读整个问题


我使用LWJGL3库制作了一个制作窗口的类。 我试图用这个类在单元测试中创建一个窗口,但它在GL.createCapabilities()方法调用中抛出一个NullPointerException。我将Intellij IDEA用于gradle和Debian 8

这不是NullPointerException的重复,因为我试图找到LWJGL3库引发此异常的原因,并且我知道此异常是什么

我已经在谷歌上搜索过了,但我没有找到为什么会发生这种情况。我试图删除
libgl1-mesa-dev
包,但没有成功

这是堆栈跟踪

java.lang.NullPointerException
        at java.util.regex.Matcher.getTextLength(Matcher.java:1283)
        at java.util.regex.Matcher.reset(Matcher.java:309)
        at java.util.regex.Matcher.<init>(Matcher.java:229)
        at java.util.regex.Pattern.matcher(Pattern.java:1093)
        at org.lwjgl.system.APIUtil.apiParseVersion(APIUtil.java:140)
        at org.lwjgl.system.APIUtil.apiParseVersion(APIUtil.java:122)
        at org.lwjgl.opengl.GL.createCapabilities(GL.java:278)
        at org.lwjgl.opengl.GL.createCapabilities(GL.java:226)
        at com.advancid.minage.gui.Window.makeCurrentContext(Window.java:85)
        at com.advancid.minage.gui.Window.<init>(Window.java:19)
        at com.advancid.minage.gui.WindowTest.workForOneWindow(WindowTest.java:9)
这是我的视窗课

package com.advancid.minage.gui;

import org.lwjgl.BufferUtils;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GLCapabilities;
import org.lwjgl.system.MemoryUtil;

import java.nio.IntBuffer;

public class Window {

    private long handle;
    private GLCapabilities capabilities = null;

    public Window(String title, int width, int height) {
        GLFW.glfwDefaultWindowHints();
        this.handle = GLFW.glfwCreateWindow(width, height, title, MemoryUtil.NULL, MemoryUtil.NULL);
        this.makeCurrentContext();
    }

    public void show() {
        GLFW.glfwShowWindow(this.handle);
    }

    public void hide() {
        GLFW.glfwHideWindow(this.handle);
    }

    public boolean shouldClose() {
        return GLFW.glfwWindowShouldClose(this.handle) == GLFW.GLFW_TRUE;
    }

    public void resize(int width, int height) {
        GLFW.glfwSetWindowSize(this.handle, width, height);
    }

    public int[] getSize() {
        IntBuffer widthBuffer = BufferUtils.createIntBuffer(1);
        IntBuffer heightBuffer = BufferUtils.createIntBuffer(1);

        GLFW.glfwGetWindowSize(this.handle, widthBuffer, heightBuffer);

        return new int[] { widthBuffer.get(), heightBuffer.get() };
    }

    public int getWidth() {
        return getSize()[0];
    }

    public int getHeight() {
        return getSize()[1];
    }

    public void setPosition(int x, int y) {
        GLFW.glfwSetWindowPos(this.handle, x, y);
    }

    public int[] getPosition() {
        IntBuffer xBuffer = BufferUtils.createIntBuffer(1);
        IntBuffer yBuffer = BufferUtils.createIntBuffer(1);

        GLFW.glfwGetWindowPos(this.handle, xBuffer, yBuffer);

        return new int[] { xBuffer.get(), yBuffer.get() };
    }

    public int getX() {
        return getPosition()[0];
    }

    public int getY() {
        return getPosition()[1];
    }

    public void destroy() {
        GLFW.glfwDestroyWindow(this.handle);
    }

    public void makeCurrentContext() {
        GLFW.glfwMakeContextCurrent(this.handle);
        GLFW.glfwSwapInterval(1);

        if (this.capabilities == null) {
            this.capabilities = GL.createCapabilities();
        } else {
            GL.setCapabilities(this.capabilities);
        }
    }

    public void update() {
        GLFW.glfwSwapBuffers(this.handle);
        GLFW.glfwPollEvents();
    }

}

我有这个错误,因为我忘了初始化GLFW。
非常奇怪,因为我在它工作之前调用了一些GLFW函数。

你能添加异常的堆栈跟踪吗?@Tom的可能副本这不是该问题的副本,因为它是引发此异常的第三方库,我知道什么是NullPointerException@Advancid你应该在你的帖子中加入你已经在互联网上跟进过的推荐信。它可以防止人们浪费时间重复同样的研究。请养成在你问的每个问题上都这样做的习惯。
package com.advancid.minage.gui;

import org.lwjgl.BufferUtils;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GLCapabilities;
import org.lwjgl.system.MemoryUtil;

import java.nio.IntBuffer;

public class Window {

    private long handle;
    private GLCapabilities capabilities = null;

    public Window(String title, int width, int height) {
        GLFW.glfwDefaultWindowHints();
        this.handle = GLFW.glfwCreateWindow(width, height, title, MemoryUtil.NULL, MemoryUtil.NULL);
        this.makeCurrentContext();
    }

    public void show() {
        GLFW.glfwShowWindow(this.handle);
    }

    public void hide() {
        GLFW.glfwHideWindow(this.handle);
    }

    public boolean shouldClose() {
        return GLFW.glfwWindowShouldClose(this.handle) == GLFW.GLFW_TRUE;
    }

    public void resize(int width, int height) {
        GLFW.glfwSetWindowSize(this.handle, width, height);
    }

    public int[] getSize() {
        IntBuffer widthBuffer = BufferUtils.createIntBuffer(1);
        IntBuffer heightBuffer = BufferUtils.createIntBuffer(1);

        GLFW.glfwGetWindowSize(this.handle, widthBuffer, heightBuffer);

        return new int[] { widthBuffer.get(), heightBuffer.get() };
    }

    public int getWidth() {
        return getSize()[0];
    }

    public int getHeight() {
        return getSize()[1];
    }

    public void setPosition(int x, int y) {
        GLFW.glfwSetWindowPos(this.handle, x, y);
    }

    public int[] getPosition() {
        IntBuffer xBuffer = BufferUtils.createIntBuffer(1);
        IntBuffer yBuffer = BufferUtils.createIntBuffer(1);

        GLFW.glfwGetWindowPos(this.handle, xBuffer, yBuffer);

        return new int[] { xBuffer.get(), yBuffer.get() };
    }

    public int getX() {
        return getPosition()[0];
    }

    public int getY() {
        return getPosition()[1];
    }

    public void destroy() {
        GLFW.glfwDestroyWindow(this.handle);
    }

    public void makeCurrentContext() {
        GLFW.glfwMakeContextCurrent(this.handle);
        GLFW.glfwSwapInterval(1);

        if (this.capabilities == null) {
            this.capabilities = GL.createCapabilities();
        } else {
            GL.setCapabilities(this.capabilities);
        }
    }

    public void update() {
        GLFW.glfwSwapBuffers(this.handle);
        GLFW.glfwPollEvents();
    }

}