Hello,
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();
//settings
setShowSettings(false);
setDisplayFps(false);
setDisplayStatView(false);
AppSettings settings = new AppSettings(true);
settings.setWidth(640);
settings.setHeight(480);
settings.setResolution(1600, 900);
settings.setUseJoysticks(true);
setPauseOnLostFocus(true);
setSettings(settings);
//GUI
createCanvas();
JmeCanvasContext ctx = (JmeCanvasContext) getContext();
//GUI
gui = new GUI(screenSize, ctx.getCanvas(), Runner.getMain());
JFrame frame = gui.getFrame();
frame.pack();
frame.setVisible(true);
System.out.println("runnable");
}
};
EventQueue.invokeLater(r);
}
//The relevant code from mygame.GUI:
private void initFrame()
{
System.out.println(6);
frame = new JFrame("Velocity Vortex");
System.out.println(7);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBackground(Color.BLUE);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
frame.setUndecorated(true);
}
This yields output:
run:
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
6
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();
System.out.println(1);
Main app = new Main();
app.start();
}
public void simpleInitApp() {}
}
The printout:
run:
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