Tag: 空指针exception

NPE使用glfwWindowShouldClose(Kotlin)

所以我刚刚开始使用本教程的一个基本的LWJGL 3程序。 我已经把所有的代码转换成Kotlin来使它工作,一切似乎都很好。 直到我到了最后他利用glfwWindowShouldClose(window) 。 我按照他所展示的方式尝试了它,并使用自己的函数调用自己的方法来替换runningvariables。 我甚至尝试用true代替它。 不幸的是,它似乎没有工作。 澄清,我的意思是,当我在我的项目中的任何地方使用glfwWindowShouldClose(window) ,任何对LWJGL函数的调用都会导致一个NPE,即使是与它无关的函数: Exception in thread “thingy” java.lang.NullPointerException at org.lwjgl.system.Checks.check(Checks.java:98) at org.lwjgl.glfw.GLFW.glfwSwapBuffers(GLFW.java:4206) at main.Window.render(main.kt:39) at main.Window.run(main.kt:15) at java.lang.Thread.run(Thread.java:745) 我用这个错误例子的代码在这里: class Window: Runnable { private val thread = Thread(this, “thingy”) private val window: Long override fun run() { while (true) { update() render() } } init { thread.start(); window […]