我有麻煩了。我想知道如何修復它約2個小時,我什麼都不知道。你能幫助我嗎? 我已經再次編寫了這段代碼,但它沒有改變任何東西,仍然不知道我在哪裏犯錯。getSize期間出現NullPointerException
public class Historia {
public ArrayList<String> tablica;
public void odczyt() throws IOException, ClassNotFoundException {
ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream("skarbonka.bin"));
tablica = (ArrayList<String>) objectInputStream.readObject();
objectInputStream.close();
int size = tablica.size();
for(int i = 0; i<size; i++){
System.out.println(tablica.get(i));
}
}
有二類:
public class Zapis {
private GregorianCalendar gregorianCalendar = new GregorianCalendar();
private Scanner scanner = new Scanner(System.in);
private Historia dodaj = new Historia();
public void plik() throws IOException {
Dane dane = new Dane();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream("skarbonka.bin"));
ArrayList<String> arrayList = new ArrayList<String>();
dane.kwota = scanner.nextInt();
dane.dzien = String.format("%tc", gregorianCalendar);
int g = dodaj.tablica.size();
for(int i=0; i<g; i++){
arrayList.add("");
arrayList.set(i, dodaj.tablica.get(i));
}
arrayList.add(dane.toString());
objectOutputStream.writeObject(arrayList);
objectOutputStream.close();
}
}
任何想法?感謝幫助!
它必須是一個存錢罐,它顯示我的帳戶狀態和當天發生了變化。 感謝您的幫助,但現在我注意到下一個差距。我的輸入只顯示最後一項。爲什麼?我想(int i = 0; i