aspose file tools*
The moose likes Game Development and the fly likes Game doesn't want to run on Windows Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Game Development
Bookmark "Game doesn Watch "Game doesn New topic
Author

Game doesn't want to run on Windows

Will Ashton
Greenhorn

Joined: Apr 26, 2014
Posts: 14

Hi Guys,
I thought that I finished my first game a few weeks ago, but when I proudly presented it to my friends, it turned out, that it doesnt seem to be working on Windows
I desperately tried to run it on my own Windows (a dust cloud ascended when the fan started, seems I didnt use it in a while ) and I saw the Problem: First I compiled a version with JDK 8, which resulted in a nice Error-Message and no program starting up at all, although I reinstalled the newest JRE. Secondly I compiled a version with JDK 6, which didnt bring up the error, but didnt startup correctly either. The window was created normally, but it seemed, like the program crashed when trying to load the graphics. Alt+F4 was the only chance to solve the problem

I wrote, compiled and "jard" the game in NetBeans, on my MacBook Pro. On Macs it seems to run without any issues...

I really hope you can help me, I'm working on this since a week and already asked a huge bunch of people...I feel a bit out of more options, as I dont have a clue, where the problems come from

You can download the game in both JDK 6 and 8, such as the sourcefiles here: DeadStorm Download


Making mistakes is human - but to really mess it up, you'll need a computer
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  17

Hi Will, welcome to CodeRanch!

It's a really silly problem actually. When you run the program from your IDE on Windows, getResource() uses the unjarred resources in your source folders. Using the system's directory separator, there will be no problem locating these resources.

However, when you run the jar file, getResource() needs to find the resources within the jar file, which *always* uses the '/' separator. If you use Windows' '\' separator instead, you will get a NullPointerException, because the resource could not be found.

When using getResource(), always use '/', as the separator.

The lesson here is, when your program runs in the IDE, but not when you run the jar, execute the jar from command line using java -jar MyJar.jar, so you can see what exceptions are thrown.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  17

Another tip: When starting a Swing application, make the frame visible only after laying out the entire application, and do it all from the event dispatch thread. A Swing application should be set up something like this:
Will Ashton
Greenhorn

Joined: Apr 26, 2014
Posts: 14

Ok, thank you a lot the problem is not totally solved now, but at least I'm making progress.
So now it sometimes starts up normally in Windows, too, but when it does, I cant control the character. The only KeyInput that seems to work is Esc and Q, to quit the game.
Sometimes I dont even get this far because its frozen again, with black or white screen
The Java command doesnt work on my Windows (dont ask me why?! It tells "command not found") and I dont have IDE's installes there...
If theres no other option, I would install one, but I prefered to leave it in "consumers-condition"... ;)
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  17

Because you probably have more file separator troubles. Do a search for "sep" on all your sources, and remove them.

The java command doesn't work because you don't have it in your PATH variable. Find the installation folder of Java, and add the bin folder to your PATH environment variable. Use the semicolon to separate it from existing paths in the variable.

From the command line:

echo %PATH%
set "PATH=C:\Program Files\Java\jre8\bin;%PATH%"
echo %PATH%
Will Ashton
Greenhorn

Joined: Apr 26, 2014
Posts: 14

Yup, forgot the soundfiles, so the game loop couldnt start up. Fixed

Ok, the Path variable, for sure. Forgot about this. Macuser ^^
When I use the commands you suggested, it works, but the changes will be disposed when I quit the command line, so I have to rewrite them every time, after starting the command line :O is this normal?

Thanks to your help the game works now, Thank you a huge lot (is this correct english well, who cares? ).
Only the sound is a bit buggy and delayed, but I already know this problem from the Mac.
I will upload the new gamefiles ASAP, if anyone wants to take a look
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18643
    
    8

Will Ashton wrote:When I use the commands you suggested, it works, but the changes will be disposed when I quit the command line, so I have to rewrite them every time, after starting the command line :O is this normal?


In Windows? Yes, that's normal. There's a way to set the environment variables permanently, but I don't remember how to do that. (Even though I've been using Windows forever!) Normally installing Java sets up the PATH variable correctly for you. Or you can write a batch file which includes the commands to set the variables and then runs your game.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  17

Huh, I didn't know that the set command didn't actually set the variable permanently.

To get to the environment variables, hit Windows+Pause/Break, then go to advanced settings and hit environment variables.

Paul, I'm pretty sure neither the JRE nor the JDK installer set the PATH variable. I always had to set it manually.
Will Ashton
Greenhorn

Joined: Apr 26, 2014
Posts: 14

Ok, who cares. I got the Mac to do this programming stuff
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18643
    
    8

Stephan van Hulst wrote:Paul, I'm pretty sure neither the JRE nor the JDK installer set the PATH variable. I always had to set it manually.


You may well be right. I think the installers used to do that, but it's been several years since I tried to run Java from the command line.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Game doesn't want to run on Windows