我开始学习如何使用LWJGL库并编写了一个简单的显示程序,但是它立即崩溃了。我正在使用Linux Mint
Exception in thread "main" java.lang.ExceptionInInitializerError
at DisplayExample.start(DisplayExample.java:10)
at DisplayExample.main(DisplayExample.java:29)
Caused by: java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at org.lwjgl.opengl.LinuxDisplay.getAvailableDisplayModes(LinuxDisplay.java:951)
at org.lwjgl.opengl.LinuxDisplay.init(LinuxDisplay.java:738)
at org.lwjgl.opengl.Display.<clinit>(Display.java:138)
... 2 more
Process finished with exit code 1
这是我写的代码:
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import java.io.File;
public class DisplayExample {
public void start(){
try{
Display.setDisplayMode(new DisplayMode(800,600));
Display.create();
}
catch(LWJGLException e){
e.printStackTrace();
System.exit(0);
}
while(!Display.isCloseRequested()){
Display.update();
}
Display.destroy();
}
public static void main(String[] args){
System.setProperty("org.lwjgl.librarypath", System.getProperty("user.dir") + File.separator + "linux");
DisplayExample d = new DisplayExample();
d.start();
}
}
在此先感谢您的答复!
这是xrandr -q
Screen 0: minimum 320 x 200, current 1920 x 1080, maximum 8192 x 8192
eDP-1 connected primary 1920x1080+0+0 (normal left inverted right x axis y axis) 345mm x 194mm
1920x1080 60.02*+ 60.01 59.97 59.96 59.93
1680x1050 59.95 59.88
1600x1024 60.17
1400x1050 59.98
1600x900 59.99 59.94 59.95 59.82
1280x1024 60.02
1440x900 59.89
1400x900 59.96 59.88
1280x960 60.00
1440x810 60.00 59.97
1368x768 59.88 59.85
1360x768 59.80 59.96
1280x800 59.99 59.97 59.81 59.91
1152x864 60.00
1280x720 60.00 59.99 59.86 59.74
1024x768 60.04 60.00
960x720 60.00
928x696 60.05
896x672 60.01
1024x576 59.95 59.96 59.90 59.82
960x600 59.93 60.00
960x540 59.96 59.99 59.63 59.82
800x600 60.00 60.32 56.25
840x525 60.01 59.88
864x486 59.92 59.57
800x512 60.17
700x525 59.98
800x450 59.95 59.82
640x512 60.02
720x450 59.89
700x450 59.96 59.88
640x480 60.00 59.94
720x405 59.51 58.99
684x384 59.88 59.85
680x384 59.80 59.96
640x400 59.88 59.98
576x432 60.06
640x360 59.86 59.83 59.84 59.32
512x384 60.00
512x288 60.00 59.92
480x270 59.63 59.82
400x300 60.32 56.34
432x243 59.92 59.57
320x240 60.05
360x202 59.51 59.13
320x180 59.84 59.32
HDMI-1 disconnected (normal left inverted right x axis y axis)
DP-1 disconnected (normal left inverted right x axis y axis)
答案 0 :(得分:0)
LWJGL在引擎盖下使用xrandr来获取屏幕分辨率by parsing xrandr -q
command output。
检查是否已安装xrandr
,并且xrandr -q
在运行Java代码的计算机上返回有效输出。然后检查您的日志中是否有Exception in XRandR.populate()
message,这将告诉您为什么LWJGL无法获得分辨率。