Friday, 6 September 2013

c# nullreference for save on load streamreader/writer

c# nullreference for save on load streamreader/writer

Ive got a question.. Ive made a programm and i wanna safe the data.
Everything is working only the ,,Loading" doesn t work.
public void Save(StreamWriter sw)
{
for (int i = 0; i < buecher.Count; i++)
{
Buch b = (Buch)buecher[i];
if (i == 0)
sw.WriteLine("ISDN ; Autor ; Titel");
sw.WriteLine(b.ISDN + ";" + b.Autor + ";" + b.Titel);
}
}
public void Load(StreamReader sr)
{
int isd;
string aut;
string tit;
while (sr.ReadLine() != "")
{
string[] teile = sr.ReadLine().Split(';');
try
{
isd = Convert.ToInt32(teile[0]);
aut = teile[1];
tit = teile[2];
}
catch
{
throw new Exception("umwandlung fehlgeschlagen");
}
Buch b = new Buch(isd, aut, tit);
buecher.Add(b);
}
}
if im doing that with an break after buecher.Add(b); than its everything
fine but he obsly shows me only 1 book... if im not using the break he
gives me an error ,,nullreference.."
Would be awesome if someone could help me best regards Ramon

No comments:

Post a Comment