I am newbie to Java so if my question doesn't make sense then please suggest to improve it so that I get my question answered.
This is how, I am initializing arrays.
public static String[][] data = null;
String[] ReadValue= new String[3];
int p = 0;
I am reading element of CSV file and trying to put in a JTable
. Below is code to feed to two dimensional array from CSV file. It throws NullPointerException
error when I try to assign value to two dimensional array.
In Line - data[p][i] = ReadValue[i].trim();
My code:
br = new BufferedReader(new FileReader(csvFile));
while ((line = br.readLine())!= null) {
ReadValue= line.split(csvSplitBy);
for (int i = 0; i < ReadValue.length; i++){
data[p][i] = ReadValue[i].trim();
// System.out.println(""+ReadValue[i].toString());
}
p++;
}
Error:
java.lang.NullPointerException
at com.srinar.graphicsTest.JtableTest.LoadCSVdata(JtableTest.java:82)
JtableTest.java:82 : - data[p][i] = ReadValue[i].trim();