开发者

How to debug code for reset functionality in Java GUI application?

I am writing some simulation code and managed to get my model running as expected. However when I reset the model (it sits on top of a large amount of code written by others that i don't have access to right now) and want to rerun it I run into trouble.

From what I have gathered from readin开发者_开发问答g posts on the site and errors i receive problems occur because of null pointer exceptions and Awt-queue errors because of some of the graphical elements running into trouble after the reset (because of those items they relate to are no longer valid).

0- What generally happens when the reset button is pressed in a simulation code? I guess (hope) everyone else has done their homework right and since i am ignorant about this i need to do some clean up of my own to make everything act nice.

1-Now what is the easiest way to fix these sort of problems that only happen after when rerunning code?

2-Also what are general guidelines for clean up of code after each run of a simulation?


Ah, OK. I can't tell you where exactly is the problem, but I have a vague memory of fixing that kind of a bug before. I think it had something to do with the graphical component's notion of "empty" value. Namely, it didn't support null as a value.

Start with examining the stack trace of the exception, and read it until you see some of your classes (i.e. the first ones which are not AWT, Swing or any other underlying class). Then take a look at the line numbers written at the stack trace in these particular classes.

If it isn't obvious what caused the exception on that line right away, just by looking at the code (more often than one would expect), then try setting a breakpoint a few lines before and step through the lines in the debugger. Hopefully, then it would be clear what went wrong.

Well, that's how I debug errors like this. Hope it helps.


I don't know the answer to items 0 and 2 so any contribution is appreciated.

I just realised what the problem was. The GUI was not being refreshed properly so it referred back to "cleaned up" items that after the first run did not exist any more and thus all sorts of weird errors were thrown...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜