I am trying to make an Arraylist with its [0] element and [1] element a string and the others doubles. I want to use these arrays for my coordinates in my other classes.
I get an NullPointerException, what am i doing wrong?
enter code here
public class ExampleTextInArrayReader
{
//naam document van ECG-patiént 1
public static final String FILE_NAME = "ecg1.txt";
//array waarin de String van ECG-waarden is omgezet in een ArrayMetDoubles
private Double[] arrayMetDoubles = new Double[722-2];
private String[] lines, gegevensPatiënt;
//velden voor patientnummer en de bijbehorende afdeling
public void main()
{
// Open the file
TextInArrayReader in = new TextInArrayReader(FILE_NAME);
// Check for errors during opening file
if (in.getError() != null)
{
System.out.println("Error opening file: " + in.getError());
System.exit(1);
}
// Read the file
String[] lines = in.getLines();
if (in.getError() != null) // check for errors during reading file
{
System.out.println("Error reading file: " + in.getError());
System.exit(1);
}
// Print file contents
for (int i = 0; i < lines.length; i++) System.out.println(lines[i]);
}
public String[] drukGegevensPatiëntAf()
{
gegevensPatiënt = new String[2];
for(int i = 0; i < 2; i++)
{
gegevensPatiënt[i] = lines[i];
}
return gegevensPatiënt;
}
public void changeArray()
{
// Get the ECG-values from the lines array and change them in doubles and put them in an arrayMetDoubles array
arrayMetDoubles = new Double[lines.length - 2];
for(int i = 2; i < arrayMetDoubles.length; i++)
{
arrayMetDoubles[i] = Double.parseDouble(lines[i + 2]);
}
}
public Double [] getLijnen()
{
changeArray();
return arrayMetDoubles;
}
}