R
RC
Vector<String []> vector = aFunction();
String[] stringArray;
for (i = 0; i < vector.size(); i++)
stringArray = (String[])vector.get(i);
public Vector<String []> aFunction() {
Vector<String []> v = new Vector<String []>Vector();
String [] sa = new String[10];
int j = 0;
while(j < 10) {
sa[0] = "zero";
sa[1] = "one";
...
sa[9] = "nine";
v.add(sa);
j++;
}
return v;
}
Comppiled by
javac -Xlint MyProgram.java
There is no warning nor error messages.
But I got run-time error
java.lang.ClassCastException: java.lang.String
I think the error is complains about this line:
stringArray = (String[])vector.get(i);
Because that is the only line doing casting.
Any help will be appreciated!
String[] stringArray;
for (i = 0; i < vector.size(); i++)
stringArray = (String[])vector.get(i);
public Vector<String []> aFunction() {
Vector<String []> v = new Vector<String []>Vector();
String [] sa = new String[10];
int j = 0;
while(j < 10) {
sa[0] = "zero";
sa[1] = "one";
...
sa[9] = "nine";
v.add(sa);
j++;
}
return v;
}
Comppiled by
javac -Xlint MyProgram.java
There is no warning nor error messages.
But I got run-time error
java.lang.ClassCastException: java.lang.String
I think the error is complains about this line:
stringArray = (String[])vector.get(i);
Because that is the only line doing casting.
Any help will be appreciated!