actually the exception originates from the call to the method getContext() , as the return value of the method cannot be cast to com.jme3.system.JmeCanvasContext.
if i try to follow your suggestion and use (i hope that is consistent with your intention):
System.out.println("context: " + this.getContext().getClass().getName());
the result is, as expected from the exception: context: com.jme3.system.NullContext
thus the error message originates from com.jme3.system.NullContext and com.jme3.system.JmeCanvasContext being unrelated: JmeCanvasContext is a subinterface of JmeContext, and NullContext only implements JmeContext…
so the real question is: Why is the context of type context:com.jme3.system.NullContext and not of type com.jme3.system.JmeCanvasContext ?
all the javadoc documentation of Application.createCanvas() seems to say, is that after the call to it, the context returned by the method getContext is supposed to be of type JmeCanvasContext .
the tutorial is not that clear to me (otherwise the problem would most propably not exist)
http://jmonkeyengine.org/wiki/doku.php/jme3:advanced:swing_canvas
on the one hand it says, i quote:
Here in the run() method, we start the jME application, create its canvas, create a Swing frame, and add everything together.
on the other, in the associated source code the application seems to be started outside of the run method, by a call to createCanvas() from main . within createCanvas there is pretty much the same as in my method initCanvas . let me cite it here for convenience:
// Code excerpt from the tutorial swing canvas: TestCanvas
public static void main(String[] args) {
JmeFormatter formatter = new JmeFormatter();
Handler consoleHandler = new ConsoleHandler();
consoleHandler.setFormatter(formatter);
Logger.getLogger("").removeHandler(Logger.getLogger("").getHandlers()[0]);
Logger.getLogger("").addHandler(consoleHandler);
createCanvas(appClass);
try {
Thread.sleep(500);
} catch (InterruptedException ex) {
}
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JPopupMenu.setDefaultLightWeightPopupEnabled(false);
createFrame();
currentPanel.add(canvas, BorderLayout.CENTER);
frame.pack();
startApp();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
System.out.println("running!");
}
});
}
public static void createCanvas(String appClass) {
AppSettings settings = new AppSettings(true);
settings.setWidth(640);
settings.setHeight(480);
try {
Class<? extends Application> clazz = (Class<? extends Application>) Class.forName(appClass);
app = clazz.newInstance();
} catch (ClassNotFoundException ex) {
ex.printStackTrace();
} catch (InstantiationException ex) {
ex.printStackTrace();
} catch (IllegalAccessException ex) {
ex.printStackTrace();
}
app.setPauseOnLostFocus(false);
app.setSettings(settings);
app.createCanvas();
app.startCanvas();
context = (JmeCanvasContext) app.getContext();
canvas = context.getCanvas();
canvas.setSize(settings.getWidth(), settings.getHeight());
}
yet obviously the tutorial code is running, mine isn’t, and i am just to blind to see the mistake…. any idea?