我要寫一個可以保存姓名和生日日期的程序,關閉程序後數據不會丟失,如果打開程序,能夠額外用戶添加到用戶根據不幸的是,我總是得到一個計算器。 - 例外,我並沒有發現這個錯誤StackOverFlow - 異常?我找不到原因:-(
<pre> package geburtstagstool;
import java.io.*;
public class GeburtstagsTool
{
public static void main (String[]args) throws Exception
{
Eintrag eintrag = new Eintrag ("Miller","000000");
}
}
class Eintrag implements Serializable
{
Eintrag [] eintrag = new Eintrag [50];
public String name;
public String gebDatum;
int i=0;
public Eintrag (String name, String gebDatum)
{
eintrag[i] = new Eintrag (name,gebDatum);
++i;
}
public void testSchreiben() throws Exception
{
ObjectOutputStream oos = new ObjectOutputStream (new FileOutputStream ("eintrag.dat"));
oos.writeObject(eintrag);
oos.close();
}
public static Eintrag testLesen() throws IOException, ClassNotFoundException
{
ObjectInputStream ois = new ObjectInputStream (new FileInputStream ("eintrag.dat"));
Eintrag eint = (Eintrag) ois.readObject();
ois.close();
return eint;
}
}
<code>
感謝您的幫助
思考的人,想:)我所有您的XXX $ /小時,如果你要我做節目:)什麼你需要的是一個列表你將存儲它們的實例。所以也許2班會解決這個更好? –
Marty