JFrame instantiation causes IDE code to stop, but .jar works

I have recently run into a error on two of my projects. The basics are this:
–I am using java.swing elements to create a GUI
–I had this code running well last week. Now, calls so instantiate JFrame cause the program to terminate without error.
–This error occurs on all my JME3 projects, whenever I instantiate a JFrame.

I first noticed the error with the following code:

//My program starts by calling this method
    public void runGame()
        Runnable r = new Runnable()
            public void run()
                Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
                AppSettings settings = new AppSettings(true);
                settings.setResolution(1600, 900);
                JmeCanvasContext ctx = (JmeCanvasContext) getContext();
                gui = new GUI(screenSize, ctx.getCanvas(), Runner.getMain());
                JFrame frame = gui.getFrame();

//The relevant code from mygame.GUI:

    private void initFrame()
        frame = new JFrame("Velocity Vortex");

This yields output:
feb 13, 2017 10:10:30 PM com.jme3.system.JmeDesktopSystem initialize
Información: Running on jMonkeyEngine 3.0.10
feb 13, 2017 10:10:30 PM com.jme3.system.Natives extractNativeLibs
Información: Extraction Directory: C:\Users\jeffr\Documents\JMonkey DEV\FTC_Velocity_Vortex_Simulation
Java Result: -1073740791
BUILD SUCCESSFUL (total time: 1 second)

Since 6 printed, I know the program ran until JFrame was instantiated. Since 7 did not print, I know the program ended there.
I have tried placing calls to instantiate JFrame in manyplaced, including the instance variable field. It always ends the program when it is run.
When the program in built into a .jar, it workswithout error.

Another test:
Mindful of the warnings on imports laid out on StackOverflow, I tired to make a simplest-possible-situation, without my large series of import statements in my former project. The entire code is:

package mygame;
import com.jme3.app.SimpleApplication;
import javax.swing.JFrame;

public class Main extends SimpleApplication 
    public static void main(String[] args) 
        JFrame j = new JFrame();
        Main app = new Main();
    public void simpleInitApp() {}

The printout:
Java Result: -1073740791
BUILD SUCCESSFUL (total time: 1 second)

Once again, the print statement after making a JFrame was never reached.
I have also looked through my JDK 1.7 libraries and have found no references to swt (as warned on StackOverflow).
When I build the first program into a .jar, it runs as expected, showing my GUI.

Does anyone have any suggestions as to how to fix this error?

Thank you very much,
Artur Hawkwing

We had exactly the same problem on windows 10 with eclipse. We never solved it.

We tried different combinations of jME libs, etc. JFrame constructor causes termination without errors. Like System,exit(0) is called

We even tried a new project with just a single file that would open a hello world JFrame. With different subsets of the different jME jars this wouldn’t work. While all stand alone packaged jars. would. We failed to isolate a particular jar in the jME set. In fact we ruled out a particular jar. But only when there are a lot of them in the build path did this then fail to start a JFrame.

this really seems to be a eclipse thing. As everything works fine from a command line.

Thanks for the reply! (Though I am sorry you have the same problem)

I am running windows 10 also, but not eclipse (I am working straight out of the editor built in with JME3). I wonder, however, if the IDE / Java version matters here. I know that JME3 runs using Java6, and eclipse can use the most recent Java versions (namely Java8), as well as older ones. Which Java version are you using in eclipse, and which is installed on your computer? I am thinking that maybe a version discrepancy could contribute to this (I use Java6 in the IDE and have Java8 on my computer).

Java 8, we tried different version of java 8. We also tried IDEA that gave the pixel format errors others sometimes have.

I tried lwjgl3 but had some other issues.

Note that i use jME current. As in the bleeding edge from git and compile it all myself.

I use Java 8 with JME 3.0. So far everything I noticed was compiler build version warning, so I guess you could switch it in JME to 8 if you need to.

1 Like

That is something I have wanted to do before, but I have never found a way of putting java 8 in JME3. Would you mind pointing me to a tutorial, if you know of one?


EDIT: Sorry, I accidentally replied to the wrong person. And thank you both very much for your help and input!

Hmm it was something so intuitive that I didn’t even search for a tutorial. What I did, I believe, I went to File → Project Properties → row “Libraries”, and there Manage Platforms… Well, should be easier with couple of screens:

You have to have JDK itself of course.

Thank you very much! I’ll give that a shot as soon as I can, and tell you how it goes.

So we just fixed it! For us at least.

This driver update made it all work 100%.

Hope that is applicable to you.

Note: that stack overflow mention of “imports” had nothing to do with ‘import statements’… which are only used by the compiler and are completely gone at runtime. He was referring to jars he had as dependencies and just happened to use the work ‘import’.

What about the new program?

Anyway, other than driver issues as others have mentioned, the only different I can think of between running from a jar and running from the SDK is that the SDK will have built the classes with its own incremental compiler. The jars will have been built from ant. If you turn off “Compile on save” in the project settings then it gets built from ANT both ways.

…more likely the driver issue that others have mentioned, though.

1 Like

Thank you!!! The patch makes it work perfectly.

Thank you for the clarificaron on imports, that makes more sense now.

The second program did not show the JFrame, but that is because I did not disable the default view of call Jframe.set Visible(true);. That test was only to see if simply instantiating JFrame caused a problem, which it did.

1 Like

Glad it helped. Also i was sort of glad we were not the only ones with problems.

It does bring up a point however. LWJGL 2.9 hasn’t been supported or at least updated for a long time. The only reason Nivida fixed it was because of minecraft.

I Need to move to lwjgl 3.x soon. That probably requires a jme3-desktop implementation in javaFX.

…I thought OP had the problem with no dependencies and just opening a JFrame…

As we did. But I suspect it is some awt/swing/java/lwjgl lib interaction or something. When some of these libs are loaded, that is when it caused problems without exit errors. Yea bit of guess on my part. But its the best i can come up with. (a lwjgl3 only project worked fine, but it doesn’t use awt :/)

I realize lwjgl3 is a fairly big shift. The move away from any swing/awt support was because the constant problems lwjgl2 and down often had with it.

I am biased to lwjgl as i know the devs well and have had the odd minor contribution. I also did a few projects where i used lwjgl exclusively.

either way. I want to move over to lwjgl3 but still had some problems the last time i tried. (last friday!)

Yeah, and I guess the “can’t use swing” bug is a pretty big one for some of us.

And I remember it messes up input handling also but we could always switch to regular JInput instead of the lwjgl2 provided one.