I am getting null-exception throw error in the following code. What can be the reason for it?
public static String[] CreateVocab(BufferedReader buffR) throws IOException{
String[] arr = null;
int i = 0;
arr[i]= null;
String line = new String();
while((line = buffR.readLine()) != null){
arr[i] = line;
i=i+1;
}
return arr;
}
Compiler is showing Null ponter exception in the code
arr[i]=null.
You haven’t created the array – and an array won’t solve your problem anyway, because it can’t resize. We don’t know the number of lines in advance.
Use a collection instead: