Непонятная ошибка: Object reference not set to an instance of an object - C#

Узнай цену своей работы

Формулировка задачи:

Код программы:
Листинг программы
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Runtime.InteropServices;
  5. using System.Windows.Forms;
  6. using Tao.FreeGlut;
  7. using Tao.OpenGl;
  8. using Tao.Platform.Windows;
  9. using Microsoft.DirectX.AudioVideoPlayback;
  10. namespace PCGE
  11. {
  12. public partial class MainForm : Form
  13. {
  14. Microsoft.DirectX.AudioVideoPlayback.Video eMovie;
  15. public MainForm()
  16. {
  17. InitializeComponent();
  18. simpleOpenGlControl1.InitializeContexts();
  19. }
  20. public void MainFormLoad(object sender, EventArgs e)
  21. {
  22. Gl.glClear(Gl.GL_COLOR_BUFFER_BIT|Gl.GL_DEPTH_BUFFER_BIT);
  23. Video.FromFile("Movie\\the_initial_roll.wmv", true);
  24. eMovie.Owner = simpleOpenGlControl1;
  25. }
  26. private void Form1_KeyDown(object sender, KeyEventArgs e)
  27. {
  28. if(e.KeyData!=Keys.Enter) return;
  29. eMovie.Stop();
  30. Gl.glClear(Gl.GL_COLOR_BUFFER_BIT|Gl.GL_DEPTH_BUFFER_BIT);
  31. }
  32. }
  33. }
После сборки SharpDevelop ругается на 25 строку. Вот что он пишет:
System.NullReferenceException: Object reference not set to an instance of an object. at PCGE.MainForm.MainFormLoad(Object sender, EventArgs e) in c:\Documents and Settings\EdMi4\Мои документы\SharpDevelop Projects\PCGE\PCGE\MainForm.cs:line 24 at System.Windows.Forms.Form.OnLoad(EventArgs e) at System.Windows.Forms.Form.OnCreateControl() at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ContainerControl.WndProc(Message& m) at System.Windows.Forms.Form.WmShowWindow(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam) at System.Windows.Forms.UnsafeNativeMethods.SendMessage(HandleRef hWnd, Int32 msg, Int32 wParam, Int32 lParam) at System.Windows.Forms.Form.SetVisibleCore(Boolean value) at System.Windows.Forms.Control.set_Visible(Boolean value) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at PCGE.Program.Main(String[] args) in c:\Documents and Settings\EdMi4\Мои документы\SharpDevelop Projects\PCGE\PCGE\Program.cs:line 19
Все было нормально пока я не перенес строчку обьявления переменной eMovie с события MainFormLoad на обьявление класса MainForm, где она в данный момент и написанна. В чем проблемма?

Решение задачи: «Непонятная ошибка: Object reference not set to an instance of an object»

textual
Листинг программы
  1.  if (simpleOpenGlControl1 != null)// могу ошибаться в правильности
  2. eMovie.Owner = simpleOpenGlControl1;

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

14   голосов , оценка 4 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут
Похожие ответы