Hi all, this is my codes.
import java.io.*;
public class Testing3
{
static double[][] mydouble;
static int a, b;
static double d;
static String[] temp;
public static void main(String args[]) throws Exception
{
try
{
BufferedReader in = new BufferedReader(new FileReader("C:\\Users\\Serene\\Documents\\Major Project\\Alignment Algorithms\\Testing2.txt")); //reading files in specified directory
String str, output="";
while ((str = in.readLine()) != null) //file reading
{
output += str;
temp = str.split(",");
for (String s : temp)
{
d = Double.parseDouble(s);
mydouble[a][b] = d;
System.out.println(mydouble[a][b]);
for(a=0; a<mydouble.length; a++)
{
for(b=0; b<mydouble[a].length; b++)
{
System.out.println(mydouble[a][b]);
}
}
}
}
in.close();
System.out.print(output);
}catch( IOException ioException ) {}
}
}
I'm having this error:
Exception in thread "main" java.lang.NullPointerException
at Testing3.main(Testing3.java:29)
I actually read my str from a text file and then parse it. After parsing it, I need to store the parsed numbers into a 2D array just like how it looks like in the original text file. I think the 2D array is empty, as after parsing it, the output printed out is individually. May I know how to I store it properly into the 2D array? As this won't be the only text file I'm going to read, hence how do I indicate the numbers of rows and columns, which will then be the size of the 2D array?