-1

I'm learning how to make a Java game with ThinMatrix's LWJGL 2 tutorials that I'm adapting to LWJGL 3. Anyway, I can't get the game to detect my monitors. This was working fine just a few days ago on the exact same system with the exact same hardware.

I have tried installing the drivers for them, uninstalling the drivers, and uninstalling the monitors completely from Device Manager. Nothing works. If you need any more information just let me know!

Here is my source code:

Main.java:

package engineTest;

import static org.lwjgl.glfw.GLFW.*;

import static renderEngine.displayManager.*;

public class Main {

    public static void main(String[] args) {

        window = glfwCreateWindow(WIDTH, HEIGHT, "Farm Game", glfwGetPrimaryMonitor(), 0);

        while(!glfwWindowShouldClose(window)) {

            updateDisplay();

        }

        glfwDestroyWindow(window);

    }

}

displayManager.java

package renderEngine;

import static org.lwjgl.glfw.GLFW.*;

import org.lwjgl.opengl.GL11;

public class displayManager {

    public static int WIDTH = 1280;
    public static int HEIGHT = 720;
    private static int FPS_CAP = 120;

    public static long window;

    public static void createDisplay() {

        glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
        glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
        glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
        glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

        GL11.glViewport(0, 0, WIDTH, HEIGHT);
    }

    public static void updateDisplay() {

        glfwPollEvents();
        glfwSwapBuffers(FPS_CAP);

    }

    public static void closeDisplay() {

        glfwDestroyWindow(window);

    }

}

Here is the error output.

Exception in thread "main" java.lang.NullPointerException
   at org.lwjgl.system.Checks.check(Checks.java:99)
   at org.lwjgl.glfw.GLFW.glfwWindowShouldClose(GLFW.java:1874)
   at engineTest.Main.main(Main.java:13)

Edit

I have been trying to debug the NullPointerException, and I know what is causing it. The problem is I don't know how to fix it. Sorry, I'm pretty new to Java.

halfer
  • 19,824
  • 17
  • 99
  • 186
takochako
  • 3
  • 4
  • 2
    Possible duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – Tobias Theel Feb 13 '18 at 22:23
  • Edit your question so the code is shown here and not on an external image service – Chisko Feb 13 '18 at 22:33
  • also, if you know what a NPE is, why don't you debug? It looks like your `window` is null – Chisko Feb 13 '18 at 22:36
  • 3
    Why do you think `glfwGetPrimaryMonitor` is the problem? Looks more as if `glfwCreateWindow` would fail. [And that's most probably because you don't call `glfwInit()` before it](https://github.com/SilverTiger/lwjgl3-tutorial/blob/master/src/silvertiger/tutorial/lwjgl/Introduction.java). – BDL Feb 13 '18 at 22:47
  • 1
    Did you see [this](https://stackoverflow.com/questions/34211489/glfwgetvideomodeglfwgetprimarymonitor-not-working) or [this](https://stackoverflow.com/questions/35486681/glfwgetprimarymonitor-is-returning-0) or [this](https://stackoverflow.com/questions/28929736/lwjgl-glfwcreatewindow-return-null)? Try googling first – Chisko Feb 13 '18 at 22:48
  • Yes. I saw all of those, Chisko. Those didn't help me because they were different problems with different answers. I always google things before posting on forums and "answer websites." If I had found the solution from those questions and answers I wouldn't have made this post. – takochako Feb 14 '18 at 00:41

1 Answers1

1

You have to call glfwInit() before you can use any other glfw method. Since this is missing, glfwCreateWindow always returns a nullptr.

BDL
  • 21,052
  • 22
  • 49
  • 55