Hallo,
ich möchte gern einen Wert aus einer Textdatei lesen. Das klappt allerdings noch nicht. Hier die Methode und der Fehler (die sysouts sind zum Debugging da):
public int getIndex(String path) throws IOException {
File file = new File(path);
System.out.println(file.exists()); //Es kommt true raus.
Scanner sc1 = new Scanner(file, "cp1252");
if (sc1.hasNext()) {
index = sc1.nextInt();
}
sc1.close();
System.out.println(index); // es sagt, die Datei ist leer
return index;
}
In der Textdatei steht eine Zahl: 235.
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "Measurement.getCharge()" because the return value of "Database.getMeasurement(int)" is null
Hier die im Fehler genannten Methoden:
public Measurement getMeasurement(int index) {
return measurementDB.get(index + 1);
}
public String getCharge() {
String temp = "";
for (MeasurementEntry m: entries) {
temp += m.getcharge() + "\n";
}
return temp;
public String getcharge() {
return charge;