【发布时间】:2015-07-10 18:28:46
【问题描述】:
我在 Ubuntu 中运行 IDEA:sudo ./idea.sh
我使用库 LWJGL 编写了一个应用程序。当我运行项目时,发现一个错误窗口:
Exception in thread "main" java.lang.IllegalStateException: Invalid X server connection specified.
at org.lwjgl.system.linux.opengl.LinuxGLContext.createFromCurrent(LinuxGLContext.java:68)
at org.lwjgl.system.linux.opengl.LinuxGLContext.createFromCurrent(LinuxGLContext.java:63)
at org.lwjgl.opengl.GLContext.createFromCurrent(GLContext.java:41)
at core.Core.createWindow(Core.java:160)
at core.Core.main(Core.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Core.java,创建窗口:
if (glfwInit() != GL_TRUE) System.out.println("#0: Failed to create window");
window = glfwCreateWindow(Settings.getWidth(), Settings.getHeight(), "Look", GL_NONE, GL_NONE);
if (window == GL_NONE) System.out.println("#1: Failed to create window");
glfwMakeContextCurrent(window);
glfwShowWindow(window);
ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(window,
(GLFWvidmode.width(vidmode) - Settings.getWidth()) / 2,
(GLFWvidmode.height(vidmode) - Settings.getHeight()) / 2);
GLContext.createFromCurrent(); // String №160
glfwSwapInterval(1);
【问题讨论】: