Re: Game of Life GUI Error
Here is the pertinent line of the stack trace: at ClickGame.prepareNextGeneration(ClickGame.java:21)
That's saying your NPE is at line 21 of ClickGame in the preprateNextGeneration() method. Which line is that? Put in some print statements before that line (or use a debugger) to figure out exactly what's going wrong.
Re: Game of Life GUI Error
Quote:
Originally Posted by
KevinWorkman
Here is the pertinent line of the stack trace: at ClickGame.prepareNextGeneration(ClickGame.java:21)
That's saying your NPE is at line 21 of ClickGame in the preprateNextGeneration() method. Which line is that? Put in some print statements before that line (or use a debugger) to figure out exactly what's going wrong.
Hi Kevin,
I inserted print messages for the StartListener actionPerformed method, inside prepareNextGeneration and inside the loops.
I find that it stops executing at the stated point:
' for (int x = 0; x < c.getX(); x++){ '
Could it be posisbly due to being unable to retreive the value of c.getX();?
Re: Game of Life GUI Error
Re: Game of Life GUI Error
Quote:
Originally Posted by
Lavace
Hi Kevin,
I inserted print messages for the StartListener actionPerformed method, inside prepareNextGeneration and inside the loops.
I find that it stops executing at the stated point:
' for (int x = 0; x < c.getX(); x++){ '
Could it be posisbly due to being unable to retreive the value of c.getX();?
You set the value of c in the constructor. But when do you call that constructor? You use that variable in a static method, which means that you aren't guaranteed to have ever set it. Make sure you understand the difference between static and non-static before you use that keyword.
That's the gist of your problem. I'm not sure where else you've crossposted the question and what help you've already received, so I'm going to leave it at that.
Re: Game of Life GUI Error
Quote:
Originally Posted by
KevinWorkman
You set the value of c in the constructor. But when do you call that constructor? You use that variable in a static method, which means that you aren't guaranteed to have ever set it. Make sure you understand the difference between static and non-static before you use that keyword.
That's the gist of your problem. I'm not sure where else you've crossposted the question and what help you've already received, so I'm going to leave it at that.
Hi Kevin,
I done some research on your suggestion and realised that I had declared the preperation method static (because I was re-using this code from my console version).
As a consequence, I had to rename all the methods to static in ClickData, change the instance variables to static and as I've just learnt, change the way the methods are called.
But I do not understand why if I remove the static references, the code still points to the same error (however, only to the prepareNextGeneration() method and no references to where).
Thank you ever so much for your help, I've been stuck on this for days.
Re: Game of Life GUI Error
I hesitate to spend too much time on this post since you crossposted to at least two other sites, so I'll just reiterate: make sure you understand the difference between static and non-static.