I am trying to read a line of numbers in string datatype then parse them into double before reading the next line. I get a nullpointerexception.
I am trying to read numbers 4 5 2 first, parse them to double, then do some other calculations before going to the second line of number which is 1 1 3 1.
double num;
String delim;
String[] tokens = null;
double[] numArray = null;
String data = "4 5 2\n1 1 3 1\n";
Scanner input = new Scanner(data);
while(input.hasNextLine())
{
delim = "[ \n]+"; //separate by spaces
tokens = data.split(delim);
for(int i = 0; i < tokens.length; i++)
{
num = Double.parseDouble(tokens[i]);
numArray[i] = num;
System.out.print(numArray[i]); //
}
}