Непонятная ошибка: Object reference not set to an instance of an object - C#
Формулировка задачи:
Код программы:
После сборки SharpDevelop ругается на 25 строку.
Вот что он пишет:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Tao.FreeGlut;
using Tao.OpenGl;
using Tao.Platform.Windows;
using Microsoft.DirectX.AudioVideoPlayback;
namespace PCGE
{
public partial class MainForm : Form
{
Microsoft.DirectX.AudioVideoPlayback.Video eMovie;
public MainForm()
{
InitializeComponent();
simpleOpenGlControl1.InitializeContexts();
}
public void MainFormLoad(object sender, EventArgs e)
{
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT|Gl.GL_DEPTH_BUFFER_BIT);
Video.FromFile("Movie\\the_initial_roll.wmv", true);
eMovie.Owner = simpleOpenGlControl1;
}
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if(e.KeyData!=Keys.Enter) return;
eMovie.Stop();
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT|Gl.GL_DEPTH_BUFFER_BIT);
}
}
}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
Листинг программы
if (simpleOpenGlControl1 != null)// могу ошибаться в правильности eMovie.Owner = simpleOpenGlControl1;