Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Help: Object reference not set to an instance of an object.

Help: Object reference not set to an instance of an object.

Scheduled Pinned Locked Moved C#
csharpcomsysadminhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gros1944
    wrote on last edited by
    #1

    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

    J 1 Reply Last reply
    0
    • G gros1944

      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

      J Offline
      J Offline
      Julian Bucknall MSFT
      wrote on last edited by
      #2

      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.

      G 1 Reply Last reply
      0
      • J Julian Bucknall MSFT

        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.

        G Offline
        G Offline
        gros1944
        wrote on last edited by
        #3

        Thank you very much!! I think I've found the problem, although is not about cf.buffCount. You're right, I'll encapsulate this function into another class, thank you very much! ;)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups