When I debug the game in eclipse the game works fine. However, when I make runnable jar out of it the game crashes when enemy gets hit, the rest of the game works fine except that part. What do I do, how do I debug runnable jar?
Put a try/catch around the function where an enemy gets hit. In the catch statement, have it print a stack trace and information on the exception caught.
Something like:
try {
enemyHit();
} catch (Exception e) {
System.out.print("RuntimeException: ");
System.out.println(e.getMessage());
e.printStackTrace();
}
Run the jar from the command line so that the printouts are still there when the jar crashes. Alternatively, write the error information to a file.
You can put the try/catch further up the stack if this doesn't catch anything. If you're not catching exceptions anywhere else, you can put this try catch all the way at the top of your stack surrounding your main loop.
I wouldn't recommend keeping the try/catch in your release code if you're fairly sure the bug is solved. There are performance issues associated with try/catch that will slow down your game if you have them surrounding frequently accessed functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With