我需要你的帮助。我不断收到此异常:-
Exception in thread "main" java.lang.IllegalStateException: Keyboard must be created before you can read events
at org.lwjgl.input.Keyboard.next(Keyboard.java:467)
at oregon.src.Controller.<init>(Controller.java:15)
at oregon.client.Oregon.start(Oregon.java:19)
at oregon.client.Oregon.main(Oregon.java:84)
我不知道如何解决它。我早些时候发布了一个问题,有人帮助了我,但后来导致了这个问题。这是(oregon.src.Controller)的代码:
package oregon.src;
import oregon.client.Oregon;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
public class Controller {
public Oregon oregon;
public Controller(Oregon oregon) throws LWJGLException {
this.oregon = oregon;
while (Keyboard.next()) {
if (Keyboard.getEventKeyState()) {
if (Keyboard.getEventKey() == Keyboard.KEY_F11) {
oregon.setFullscreen();
}
}
}
}
}
这是(oregon.client.Oregon)的代码:
package oregon.client;
import oregon.src.Controller;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
public class Oregon {
public static DisplayMode normal = new DisplayMode(640, 640);
public Controller controller;
public static boolean fullscreen = false;
public void start() {
try {
controller = new Controller(this);
} catch (LWJGLException e1) {
e1.printStackTrace();
}
try {
create();
} catch (LWJGLException e) {
stop(e);
}
while (!Display.isCloseRequested()) {
events();
Display.update();
}
Display.destroy();
}
public void events() {
try {
new Controller(this);
} catch (LWJGLException e) {
e.printStackTrace();
}
}
public void setFullscreen() {
try {
if (!fullscreen) {
Display.setFullscreen(true);
fullscreen = true;
} else if (fullscreen) {
Display.setDisplayMode(normal);
fullscreen = false;
}
} catch (LWJGLException e) {
stop(e);
}
}
public static void create() throws LWJGLException {
if (fullscreen) {
Display.setFullscreen(true);
} else if (!fullscreen) {
Display.setDisplayMode(normal);
}
Keyboard.create();
Display.create();
}
public void stop() {
System.exit(0);
Display.destroy();
}
public void stop(Exception e) {
e.printStackTrace();
System.exit(0);
Display.destroy();
}
public static void main(String args[]) {
Oregon oregon = new Oregon();
oregon.start();
}
}
如果有人可以帮助我,我将不胜感激。谢谢你。
编辑:- 现在我收到此错误。
Exception in thread "main" java.lang.IllegalStateException: Display must be created.
at org.lwjgl.input.Keyboard.create(Keyboard.java:319)
at oregon.src.Controller.<init>(Controller.java:19)
at oregon.client.Oregon.start(Oregon.java:19)
at oregon.client.Oregon.main(Oregon.java:84)