• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Game doesn't want to run on Windows

 
Greenhorn
Posts: 27
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 27
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 27
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 27
Netbeans IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, who cares. I got the Mac to do this programming stuff
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Stinging nettles are edible. But I really want to see you try to eat this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic