General Java Questions II
For example:
public void recurseList( List l )
the generic List ensure that you can use every List for this method (ArrayList,
AbstractList, Vector...), so your calling method can be:
ArrayList l = new ArrayList(); or
Vector l = new Vector();
recurseList( l );
Without any problem.
by Davide Bianchi
Q: I got a problem with an array/vector...
I got a problem with an array/vector.
my class contains a member:
static Vector quad[][];
....
in my constructor I got:
Vector quad[][] = new Vector[row][col];
for (int i = 0; i < row; i++){
for (int j = 0; j < col; j++){
quad[i][j] = new Vector (0,1);
}
}
// row and col are int between (10..50) it s a big I know, but that
might not be the problem
My PROBLEM (and I don t know what to do, really), I can t access quad[x][y] outside
of the constructor!!!! Within the constructor I ve got full access on quad[x][x]. Java
(1.2) returns a NullPointerException on any method except within the constructor!!!
What s my fault!???
Answer: I guess you shouldn t write Vector here:
Vector quad[][] = new Vector[row][col];
so, the correct variant may be:
quad[][] = new Vector[row][col];
I guess You just overridden your static variable with one defined in your constructor:
Vector quad[][].
Thus, you re initializing NOT your class scope static variable but your
constructor scope quad. It s not reachable outside the constructor. And as for static
quad, it has never been initialized! And a first reference to it causes
NullPointerException. I guess. I hope I m right :)
Xao Rom
file:///F|/a_jsite/350_tips/general_java II.htm (13 of 14) [2001 07 08 11:24:53]
footer
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved