Got problem on accessing public (global) array
I had this problem and i tried to search but could not find similar problems. There is an array i want to declare globally, which in java would be a "public variable", if my understanding is correct.
The size of this array is not determined when i define it. The size will be determined until the last element of the array is filled in a while loop.
here's my code, Thank you all in advance.
Code:
public class Calc {
public static int chunk = 0;
public static int [] count;
public static void screen(){
String tmpwords;
StringTokenizer tokenizer;
boolean stop = false;
try {
InputStream srcdata = new FileInputStream("20090506.xml");
BufferedReader in = new BufferedReader(new InputStreamReader(srcdata, "UTF8"));
String tmp=in.readLine();
while(!tmp.startsWith("</Do")){
while(!tmp.startsWith("</t")){
tokenizer = new StringTokenizer(tmp," ");
while(tokenizer.hasMoreTokens()){
tmpwords = tokenizer.nextToken();
//############################################
//#### the following line is the problem #######
//##############################################
Calc.count[Calc.chunk]++;
}
tmp=in.readLine();
}
Calc.chunk++;
}
in.close();
}
catch (Exception e) {
System.err.println("Read sourse file exception " + e.toString());
}
}
public static void main(String[] argv) {
screen();
}
}