You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
General <strong>Java</strong> Questions II<br />
recurseList( l );<br />
Without any problem.<br />
by Davide Bianchi<br />
Q: I got a problem with an array/vector...<br />
I got a problem with an array/vector.<br />
my class contains a member:<br />
static Vector quad[][];<br />
....<br />
in my constructor I got:<br />
Vector quad[][] = new Vector[row][col];<br />
for (int i = 0; i < row; i++){<br />
for (int j = 0; j < col; j++){<br />
quad[i][j] = new Vector (0,1);<br />
}<br />
}<br />
// row and col are int between (10..50) -- it's a big I know, but that<br />
might not be the problem<br />
My PROBLEM (and I don't know what to do, really), I can't access quad[x][y] outside<br />
of the constructor!!!! Within the constructor I've got full access on quad[x][x]. <strong>Java</strong><br />
(1.2) returns a NullPointerException on any method except within the constructor!!!<br />
What's my fault!???<br />
Answer: I guess you shouldn't write Vector here:<br />
Vector quad[][] = new Vector[row][col];<br />
so, the correct variant may be:<br />
quad[][] = new Vector[row][col];<br />
I guess You just overridden your static variable with one defined in your constructor:<br />
Vector quad[][].<br />
Thus, you're initializing NOT your class-scope static variable but your<br />
constructor-scope quad. It's not reachable outside the constructor. And as for static<br />
quad, it has never been initialized! And a first reference to it causes<br />
NullPointerException. I guess. I hope I'm right :)<br />
--<br />
Xao Rom<br />
file:///F|/350_t/350_tips/general_java-II.htm (12 of 13) [2002-02-27 21:18:24]