我正在嘗試使用其[0]元素和[1]元素創建一個字符串,其他元素加倍。我想在其他類中使用這些數組作爲我的座標。將字符串更改爲數組中的兩倍
我得到一個NullPointerException,我做錯了什麼?
進入這裏
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;
}
}
WHere你是否得到例外? –
ExampleTextInArrayReader.changeArray(ExampleTextInArrayReader.java:48) – user3111770
這是哪一行? –