[Solved] Dist\MyGame.jar doesn't work on desktop, does in cmd (inputStream issue)

I’m trying to deploy my game, but the jar (and by extension, the windows EXE file) doesn’t like running by double-clicking in file viewer. What it does is it loads up the game enough to see the jME splash page (with the screen settings) but as soon as the game itself loads, it crashes with a NullPointerException (more specifically when I try to do some SAX parsing. I suspect the issue is difficulty with the assets folder?) Game runs fine in SDK.

I actually managed to narrow down when the jar likes the command prompt more: when i run java -jar dist\MyGame.jar inside the game’s project directory. Oddly enough, outside of this directory I get the same issue in cmd as double clicking (crashes after launch). So I’m guessing the error is about application context, if that’s the right term, which I know nothing about how to configure and don’t know what the google key terms are for this problem :confounded: I was wondering if jME/netbeans has some option that deals with this?

Some more details that may be relevant: I’m running Windows 8.1 x64, my JRE is 1.8 which I freshly installed this morning, I’m using JDK 1.7 in jME, I only have the lwjgl-minimum library in use, path points to JRE 1.8, and the default windows launcher is javaw.exe (switching to opening with java.exe doesn’t change the issue and instead the program shows the command prompt and immediately closes)

Let me know if I need to post any more info… very confusing. Thanks in advance!

Sounds like maybe you are trying to read things directly from the assets folder… which doesn’t exist in an actual distribution.

To help more we’d have to see the 99% of the useful part of the NPE and some code, probably.

To me it sounds like some classpath issues. Since the current directory in cmd is added to the classpath, and not the path of the jar you are missing some dependecies.

Are you reading from any file that is not part of the assets folder?

Stacktrace please!

Create a BAT file and add the java run command to it, in the same directory as the jar. At the end of the BAT script add a:


Then double click .bat file to run it and you should see the stacktrace if there is any. Alternatively, you could try using Powershell since you are on Windows which doesn’t require a pause command.

Stacktrace: java.io.FileNotFoundException: assets\Scenes\test_large_map.tmx (The system cannont find the path specified)
at java.io.FileInputStream.open0 (Native Method)

java.lang.IllegalArgumentException: InputStream cannot be null
at javax.xml.parsers.SAXParser.parse

at mapPack.MapLoader.makeTiledMap

This is created if I java -jar the program in the same folder as the jar or outside the directory of the project. Runs fine inside the project’s folder… which I suspect now like what pspeed said may have to do with reading the assets folder directly:

try {
            is = new BufferedInputStream(new FileInputStream("assets/Scenes/" + name + ".tmx"));
        } catch (FileNotFoundException ex) {
            Logger.getLogger(MapLoader.class.getName()).log(Level.SEVERE, null, ex);
        try {
            map = tmxReader.readMap(is);
        } catch (Exception ex) {
            Logger.getLogger(MapLoader.class.getName()).log(Level.SEVERE, null, ex);

        TileSet tileSet = map.getTileSet(0); //throws the NPE that I saw


 public Map readMap(InputStream IS) throws Exception {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        SAXParser saxParser = factory.newSAXParser();
        saxParser.parse(IS, new SAXStub());
        return (map);

are where the errors occurred. Thanks for all of your responses!

You have to load the asset from the classpath, without the “assets” prefix.

is = new BufferedInputStream(this.getClass().getResourceAsStream("/Scenes/" + name + ".tmx"));

And that appears to solve the problem! Thank you very much!