Re: NullPointerException when GLWindow.setVisible(true) is called?
Posted by
Xerxes Rånby on
Feb 07, 2014; 2:58pm
URL: https://forum.jogamp.org/NullPointerException-when-GLWindow-setVisible-true-is-called-tp4031493p4031498.html
Pepe1 wrote
Right, sorry. Let's try again.
The stack trace:
Exception in thread "main" java.lang.RuntimeException: java.lang.NullPointerException
at jogamp.newt.DefaultEDTUtil.invokeImpl(DefaultEDTUtil.java:246)
at jogamp.newt.DefaultEDTUtil.invoke(DefaultEDTUtil.java:160)
at jogamp.newt.DisplayImpl.runOnEDTIfAvail(DisplayImpl.java:427)
at jogamp.newt.WindowImpl.runOnEDTIfAvail(WindowImpl.java:1988)
at jogamp.newt.WindowImpl.setVisible(WindowImpl.java:978)
at jogamp.newt.WindowImpl.setVisible(WindowImpl.java:983)
at com.jogamp.newt.opengl.GLWindow.setVisible(GLWindow.java:441)
at MainWindow.setVisible(MainWindow.java:67)
at Main.<init>(Main.java:29)
at Main.main(Main.java:33)
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:120)
Caused by: java.lang.NullPointerException
at Menu.drawBackground(Menu.java:37)
at Menu.display(Menu.java:29)
at MainWindow.display(MainWindow.java:86)
at jogamp.opengl.GLDrawableHelper.displayImpl(GLDrawableHelper.java:665)
at jogamp.opengl.GLDrawableHelper.display(GLDrawableHelper.java:649)
at jogamp.opengl.GLAutoDrawableBase$2.run(GLAutoDrawableBase.java:399)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1119)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:994)
at com.jogamp.newt.opengl.GLWindow.display(GLWindow.java:621)
at jogamp.opengl.GLAutoDrawableBase.defaultWindowResizedOp(GLAutoDrawableBase.java:244)
at com.jogamp.newt.opengl.GLWindow.access$200(GLWindow.java:111)
at com.jogamp.newt.opengl.GLWindow$2.windowResized(GLWindow.java:133)
at jogamp.newt.WindowImpl.consumeWindowEvent(WindowImpl.java:3516)
at jogamp.newt.WindowImpl.sendWindowEvent(WindowImpl.java:3454)
at jogamp.newt.WindowImpl.setVisibleActionImpl(WindowImpl.java:957)
at jogamp.newt.WindowImpl$VisibleAction.run(WindowImpl.java:969)
at com.jogamp.common.util.RunnableTask.run(RunnableTask.java:112)
at jogamp.newt.DefaultEDTUtil$NEDT.run(DefaultEDTUtil.java:369)
(I think) All relevant code:
public class MainWindow implements GLEventListener
{
private GLWindow glWindow;
private GLCapabilities caps;
private String name;
private int sizeX;
private int sizeY;
private String state;
private State menu;
private State game;
public MainWindow(String windowName, int x, int y, boolean doubleBuffering, boolean hardwareAcceleration)
{
this.name = windowName;
this.sizeX = x;
this.sizeY = y;
setCaps(doubleBuffering, hardwareAcceleration);
initGLWindow();
}
private void setCaps(boolean doubleBuffering, boolean hardwareAcceleration) //I call this with both vars being true
{
caps = new GLCapabilities(GLProfile.get(GLProfile.GL2));
caps.setDoubleBuffered(doubleBuffering);
caps.setHardwareAccelerated(hardwareAcceleration);
}
private void initGLWindow()
{
glWindow = GLWindow.create(caps);
glWindow.setTitle(name);
glWindow.setSize(sizeX, sizeY);
glWindow.setAutoSwapBufferMode(true);
glWindow.addGLEventListener(this);
glWindow.setVisible(true);
}
public void addMouseListener(MouseListener l)
{
glWindow.addMouseListener(l);
}
public void addKeyListener(KeyListener l)
{
glWindow.addKeyListener(l);
}
public void setState(String state)
{
this.state = state;
}
public void setMenu(State menu)
{
this.menu = menu;
}
public void setGame(State game)
{
this.game = game;
}
}
It's called like so:
public class Main
{
private MainWindow window;
private StateBridger bridger;
private Game game;
private Menu menu;
private UserInput input;
public Main()
{
window = new MainWindow("testest", 640, 480, true, true);
input = new UserInput(window);
menu = new Menu(window);
game = new Game(window);
bridger = new StateBridger(menu, game);
menu.setBridger(bridger);
menu.setInput(input);
game.setBridger(bridger);
game.setInput(input);
window.setMenu(menu);
window.setGame(game);
menu.start();
window.setState("Menu");
}
public static void main(String[] args)
{
new Main();
}
}
I really appreciate you guys trying to help me.
Still not enough code added to compile and test it.
where is the Menu class?
Caused by: java.lang.NullPointerException
at Menu.drawBackground(Menu.java:37)
If you have a github account you can upload all the java code needed to compile and run this to a github repository and share that.
cheers
Xerxes