Help: Object reference not set to an instance of an object.
-
Here's part of my project: public class NetworkStats { private Form1 form; private AxMicrosoft.MediaPlayer.Interop.AxWindowsMediaPlayer player; private ConfigResult cf; public NetworkStats(Form1 form1, AxMicrosoft.MediaPlayer.Interop.AxWindowsMediaPlayer player1, ConfigResult cf1) { form = form1; player = player1; cf = cf1; } public FileStruct FileStats() { string path; DirectoryInfo dir; FileStruct fs = new FileStruct(); path = cf.pathLog + "\\" + player.currentMedia.name + "\\"; dir = new DirectoryInfo(cf.pathLog); dir.CreateSubdirectory(player.currentMedia.name); if(cf.buffCount) { try { fs.fileStats = new FileStream(path + "Stats.txt", FileMode.Create, FileAccess.Write); fs.swStats = new StreamWriter(fs.fileStats); } catch (Exception e) { Console.WriteLine(e.Message); } } if(cf.currBW) { try { fs.fileBW = new FileStream(path + "currBW.txt", FileMode.Create, FileAccess.Write); fs.swBW = new StreamWriter(fs.fileBW); } catch (Exception e) { Console.WriteLine(e.Message); } } if(cf.currBR) { try { fs.fileBR = new FileStream(path + "currBR.txt", FileMode.Create, FileAccess.Write); fs.swBR = new StreamWriter(fs.fileBR); } catch (Exception e) { Console.WriteLine(e.Message); } } if(cf.currFR) { try { fs.fileFR = new FileStream(path + "currFR.txt", FileMode.Create, FileAccess.Write); fs.swFR = new StreamWriter(fs.fileFR); } catch (Exception e) { Console.WriteLine(e.Message); } } return fs; } public void initStats() { FileStruct fs; fs = FileStats(); while (Form1.videoParat != true) { try { form.BitRate.Text = (player.network.bitRate).ToString() + " Bps"; if(cf.currBR) { fs.swBR.WriteLine(player.network.bitRate.ToString() + " " + player.controls.currentPositionString); } form.BW.Text = (player.network.bandWidth).ToString() + " Bps"; if(cf.currBW) { fs.swBW.WriteLine(player.network.bandWidth.ToString() + " " + player.controls.currentPositionString); } form.buffCount.Text = (player.network.bufferingCount).ToString(); form.buffProgress.Text = (player.network.bufferingProgress).ToString(); form.buffTime.Text = (player.network.bufferingTime).ToString() + " mseg"; form.downPr
-
Here's part of my project: public class NetworkStats { private Form1 form; private AxMicrosoft.MediaPlayer.Interop.AxWindowsMediaPlayer player; private ConfigResult cf; public NetworkStats(Form1 form1, AxMicrosoft.MediaPlayer.Interop.AxWindowsMediaPlayer player1, ConfigResult cf1) { form = form1; player = player1; cf = cf1; } public FileStruct FileStats() { string path; DirectoryInfo dir; FileStruct fs = new FileStruct(); path = cf.pathLog + "\\" + player.currentMedia.name + "\\"; dir = new DirectoryInfo(cf.pathLog); dir.CreateSubdirectory(player.currentMedia.name); if(cf.buffCount) { try { fs.fileStats = new FileStream(path + "Stats.txt", FileMode.Create, FileAccess.Write); fs.swStats = new StreamWriter(fs.fileStats); } catch (Exception e) { Console.WriteLine(e.Message); } } if(cf.currBW) { try { fs.fileBW = new FileStream(path + "currBW.txt", FileMode.Create, FileAccess.Write); fs.swBW = new StreamWriter(fs.fileBW); } catch (Exception e) { Console.WriteLine(e.Message); } } if(cf.currBR) { try { fs.fileBR = new FileStream(path + "currBR.txt", FileMode.Create, FileAccess.Write); fs.swBR = new StreamWriter(fs.fileBR); } catch (Exception e) { Console.WriteLine(e.Message); } } if(cf.currFR) { try { fs.fileFR = new FileStream(path + "currFR.txt", FileMode.Create, FileAccess.Write); fs.swFR = new StreamWriter(fs.fileFR); } catch (Exception e) { Console.WriteLine(e.Message); } } return fs; } public void initStats() { FileStruct fs; fs = FileStats(); while (Form1.videoParat != true) { try { form.BitRate.Text = (player.network.bitRate).ToString() + " Bps"; if(cf.currBR) { fs.swBR.WriteLine(player.network.bitRate.ToString() + " " + player.controls.currentPositionString); } form.BW.Text = (player.network.bandWidth).ToString() + " Bps"; if(cf.currBW) { fs.swBW.WriteLine(player.network.bandWidth.ToString() + " " + player.controls.currentPositionString); } form.buffCount.Text = (player.network.bufferingCount).ToString(); form.buffProgress.Text = (player.network.bufferingProgress).ToString(); form.buffTime.Text = (player.network.bufferingTime).ToString() + " mseg"; form.downPr
Well, I would guess that, since you only create the swStats member when cf.buffCount is true, cf.buffCount is false. Your best bet is to use the debugger to trace through your application. Check that swStats is being created properly, and if it is what else is happening as your app runs. Also, I would define a new class that encapsulates the "create a filestream, create a stream writer" code. You're replicating it several times. Cheers, Julian Program Manager, C# This posting is provided "AS IS" with no warranties, and confers no rights.
-
Well, I would guess that, since you only create the swStats member when cf.buffCount is true, cf.buffCount is false. Your best bet is to use the debugger to trace through your application. Check that swStats is being created properly, and if it is what else is happening as your app runs. Also, I would define a new class that encapsulates the "create a filestream, create a stream writer" code. You're replicating it several times. Cheers, Julian Program Manager, C# This posting is provided "AS IS" with no warranties, and confers no rights.