问题
While doing some homework that works with some swing gui components, my program started crashing seemingly at random. That is, it starts, runs for a short time, and then crashes. I don't get any errors in the console, it's just a straight up crash.
I don't doubt that it is something I wrote, and I'm more than happy to show code if anyone wants to look at it, but is there anything that I can do myself to track down what might be the cause of my crashes?
Some other information that might be useful:
- I'm using eclipse, and the debugger doesn't seem to do anything that helps me with this (program still crashes).
- I didn't notice any issues like this until I started to add event handling.
- I'm using Windows 10.
- Occasionally, nothing is drawn in the window I create. Exiting and then running the program again will cause it to work.
回答1:
Some possible heuristics:
Crashes that occur seemingly at random suggest incorrect synchronization; look for event dispatch thread violation using one of the approaches cited here.
Verify that all exception handlers produce diagnostic output; run from the command line to ensure that diagnostic output has not been inadvertently redirected.
Try running under the aegis of a different debugger, e.g. NetBeans.
Try running under the aegis of a profiler.
Try a different version of the JDK/JRE.
Try a different host OS.
来源:https://stackoverflow.com/questions/30207220/how-to-track-down-seemingly-random-crashes-in-java