Re: Enum list
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Joshua Cranmer <Pidgeot18@verizon.invalid> writes:
On 03/26/2011 12:26 PM, Merciadri Luca wrote:
==
Exception in thread "main" java.lang.NullPointerException
at Tableau.createRandom(Tableau.java:25)
==
where my L.25 uses State.DEAD.
And what is line 25? Chances are it uses more than just State.DEAD,
and one of those other objects could be null.
As was pointed out earlier, we need more context, as what you think
may be the problem is probably not what the problem actually is
(especially since you would have fixed it if you actually already
understood the problem).
Thanks for the positive answers (well, negative might stay in your
keyboard; better for everybody).
I've done some tests, and the fact is that
==
System.out.println(tableau.setOfCells[1][1]);
==
outputs null in the console (once tableau has been created). Neither
tableau nor tableau.setOfCells point to null, but
tableau.setOfCells[1][1] points to null.
I don't know if it is normal, but it might be a cause
for what happens at L.25, which is
==
tableau.setOfCells[i][j].setState(State.DEAD);
==
where the error is due to the tableau.setOfCells[i][j] part of this
expression (probably because tableau.setOfCells[i][j] points to null
as I mentioned earlier). I can advance this because I tested the
..setState method (which thus acts on Cell instantiations), and the
State.DEAD method, both thoroughly, without any problem.
Notes:
* I've got a Cell class where are some variables such as a State:
==
public class Cell {
private State state;
// ...
}
==
* I've got a Tableau class where setOfCells follows these rules:
==
public class Tableau {
// ...
public Cell[][] setOfCells;
public Tableau(int n, int s) { // constructor
setOfCells = new Cell[n][n];
// ...
}
}
==
* I've got a setState method in the Cell class:
==
public void setState(State newState) { // mutator
state = newState;
}
==
* I've got a State enum defined in a State.java file:
==
public static enum State {
DEAD, LIVING
}
==
Any idea?
- --
Merciadri Luca
See http://www.student.montefiore.ulg.ac.be/~merciadri/
- --
If you fall off a cliff, you might as well try to fly. After all, you got nothing to lose.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/>
iEYEARECAAYFAk2OWsgACgkQM0LLzLt8Mhx4wACghIpd6UT3C4yw786RC+5oB1GQ
WssAniC/7rhLA/KOiAgpu3yTE5mbooap
=8zuj
-----END PGP SIGNATURE-----