This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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
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.
The mind is a strange and wonderful thing. I'm not sure that it will ever be able to figure itself out, everything else, maybe. From the atom to the universe, everything, except itself.
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:
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"... ;)
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:
set "PATH=C:\Program Files\Java\jre8\bin;%PATH%"
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
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.