TestSafeCanvas errors

I’m trying to run a template file TestSafeCanvas, but I get errors:
java.lang.ClassNotFoundException: jme3test.post.TestRenderToTexture
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:375)
at jme3test.awt.TestCanvas.createCanvas(TestCanvas.java:214)
at jme3test.awt.TestCanvas.main(TestCanvas.java:260)
Exception in thread “main” java.lang.NullPointerException: Cannot invoke “com.jme3.app.LegacyApplication.setPauseOnLostFocus(boolean)” because “jme3test.awt.TestCanvas.app” is null
at jme3test.awt.TestCanvas.createCanvas(TestCanvas.java:226)
at jme3test.awt.TestCanvas.main(TestCanvas.java:260)
Java Result: 1

Can anyone please tell me what I’m doing wrong?

Could we we your source for the (minimal that reproduces the problem) application? Or if this is an example project somewhere then could you link to it

1 Like
package jme3test.awt;

import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import com.jme3.system.AppSettings;
import com.jme3.system.JmeCanvasContext;
import java.awt.Canvas;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;

public class TestSafeCanvas extends SimpleApplication {

    public static void main(String[] args) throws InterruptedException{
        AppSettings settings = new AppSettings(true);

        final TestSafeCanvas app = new TestSafeCanvas();

        JmeCanvasContext context = (JmeCanvasContext) app.getContext();
        Canvas canvas = context.getCanvas();
        canvas.setSize(settings.getWidth(), settings.getHeight());



        JFrame frame = new JFrame("Test");
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {





    public void simpleInitApp() {

        Box b = new Box(1, 1, 1);
        Geometry geom = new Geometry("Box", b);
        Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
        mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
1 Like

That test is known to fail with LWJGL v3:

As I understand it, the workarounds are (1) to use LWJGL v2 (in other words, jme3-lwjgl instead of jme3-lwjgl3) or else (2) avoid using Swing/AWT.

I get these errors both in jMonkeyEngine SDK and in IDEA, experiments in jme3-lwjg do not change the result. And disabling swing is unacceptable for me, since I am interested in the combination with swing, this is the essence of this example

If you can read around all of the extra stuff, here is an app that builds an IDE-like window with a JME window in it.

No matter what, lwjgl3 won’t work… it has to be lwjgl2.

Just tried TestSafeCanvas and it works fine for me with lwjgl2.

1 Like

You said you tried the SDK. Did you do it the following way:

  1. File | New Project,
  2. Choose Category: JME3, JME3 Tests
  3. Run project
  4. Choose TestSafeCanvas

For me, this works out of the box.

Edit: Instead running with TestChooser, find TestSafeCanvas in IDE and run it independently (in SDK, right click the file in the projects view and select run.

By the way, I noticed when running via TestChooser it bypasses the main method (which has all the swing stuff) and runs it as a regular JME app (not embedded in JFrame).

I needed to change mainClassName in jme3-examples build.gradle to jme3test.awt.TestSafeCanvas to successfully test the app.

For reference, this is how it should look like. (see the Windows title, it is named “Test”)

This seems to be the case yes. Is it correctly formulated the whole thing? TestChooser assumes that everything that is LegacyApplication is invoked differently, main method it used if this is not the case (in TestSafeCanvas is should always use the main?).