NullPointerException with glfwGetPrimaryMonitor()

Started by takochako, February 13, 2018, 17:59:39

Previous topic - Next topic

takochako

I'm just learning how to code java (yes, I know, this probably isn't the best way to start learning but whatever) with ThinMatrix's LWJGL 2 tutorials that I'm adapting to LWJGL 3. Anyway, I can't get the game to detect my monitors. 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 a paste with my source code:

https://pastebin.com/aQnyCJik

Sorry! I forgot to include the actual console error output! xD

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)

KaiHH

Not only is using OpenGL and GLFW to start learning Java not the best way; it is the absolute worst way to do it! That's not because I'm generally opposed to LWJGL - quite the contrary actually. But it is because using OpenGL, GLFW and all the other native libraries which LWJGL "merely" provides bindings for, forces you to learn the APIs of those libraries rather than Java, the language.
Remember that LWJGL provides Java bindings to those native libraries, such as OpenGL, OpenAL, OpenCL, Vulkan, and a whole lot of other libraries, in the most direct way possible, trying to get as little "Java language" in there as possible, which quite often means that the bindings are just a bunch of static methods and static integer fields in a class named after the library that class provides the Java bindings for. That is to mimic the C interface those languages typically come with and which is known to experienced developers using those libraries and is by far the most common way of using those libraries.

What this ultimately means is the following, depending on your actual goal:
1. When you actually want to learn Java, the language, and the typical classes you come in contact with using Java (such as the Collection Framework), do not start using OpenGL/GLFW through LWJGL. Probably start with one of the tutorials provided by Oracle on their sites.
2. When you actually do want to learn OpenGL and GLFW, using Java and LWJGL to do so is also a very bad idea, because you will feel like needing to google for "LWJGL3 tutorial" or "How do I draw a triangle with LWJGL3?". Those are bad questions to begin with, because again LWJGL only provides _bindings_ to native libraries such as OpenGL and GLFW. When you want to learn those libraries, directly include those library names in your searches and do not mention LWJGL/LWJGL3. This will give you the best possible anwers but will result in all code examples to be in C or C++. GET COMFORTABLE READING C/C++ when you want to learn OpenGL and GLFW!

Now, to solve your direct problem of your code not working: You have multiple errors in your code, which you will perfectly be able to resolve when you look out for other working code first. For example, start with lwjgl.org and the LWJGL3 GitHub repository. Then again, search for working OpenGL/GLFW code on the internet not relating to LWJGL/LWJGL3.