System.NullReferenceException发生在 [英] System.NullReferenceException occurred in

查看:94
本文介绍了System.NullReferenceException发生在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C#.NET新手做一个小型学校项目,但我收到了一个

奇怪的错误信息。


'' System.windows.forms.dll中发生了System.NullReferenceException事件

附加信息:对象引用未设置为

对象的实例。


正如我的参考文献所示,我似乎在使用旧框架(1.0.3705)来支持

这个,但是重新引用了更新的框架(1.1.4322)dll 's产生了

同样的错误。当我正在尝试编译一个完全托管的项目时,会发生这种情况。即使从头开始尝试编译

空表也会发生这种情况。


如果您阅读了我所包含的旧主题,您可以看到他将整个项目的

源路径更改为未放入

MyDocuments文件夹中的内容。我做了完全相同的事情并且有效,我的问题是为什么?所有其他应用程序(到目前为止)编译完美无瑕,只有这些C#Windows应用程序项目失败了。


问候,


AndreasWirén


操作系统:带有所有最新修补程序和更新的Windows XP Professional SP1。


using System;

使用System.Drawing;

使用System.Collections;

使用System.ComponentModel;

使用System。 Windows.Forms;

使用System.Data;


命名空间WindowsApplication1

{

// /< summary>

/// Form1的摘要说明。

///< / summary>

公共类Form1:系统.Windows.Forms.Form

{

///< summary>

///所需的设计师变量。

///< / summary>

private System.ComponentModel.Container components = null;


public Form1()

{

//

// Windows窗体需要设计师支持

//

InitializeComponent();


//

// TODO:在InitializeComponent调用后添加任何构造函数代码

//

}


///< summary>

///清理正在使用的所有资源。

///< / summary>

protected override void Dispose(bool disposing)

{

if(处理)

{

if(components!= null)

{

components.Dispose();

}

}

base.Dispose(disposing);

}


#region Windows窗体设计器生成的代码

///< summary>

///设计器支持所需的方法 - 不要使用代码编辑器修改

///此方法的内容。

///< / summary>

private void InitializeComponent()

{

//

// Form1

//

this.AutoScaleBaseSize = new System.Drawin g.Size(5,13);

this.ClientSize = new System.Drawing.Size(292,266);

this.Name =" Form1" ;;

this.Text =" Form1";

this.Load + = new System.EventHandler(this.Form1_Load);


}

#endregion


///< summary>

///应用程序的主要入口点。

///< / summary>

[STAThread]

static void Main()

{

Application.Run(new Form1());

}


private void Form1_Load(object sender,System.EventArgs e )

{


}

}

}

< a rel =nofollowhref =http://groups.google.se/groups?hl=sv&lr=&ie=UTF-8&oe=UTF-8&threadm=6FADa.54216%24g33.749173 %40weber.videotron.net& rnum = 6& prev = / groups%3Fq%3D%2522Applicatarget =_ blank> http://groups.google.se/groups?hl=sv...3D%2522Applica

tion.Run(新%2BForm1())%253B%2522%2B%2522objec t%2B参考%2Bnot%2Bset%2522

%26hl%3Dsv%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3D6FADa.54216%2524g33.74

9173%2540weber.videotron.net%26rnum%3D6

Hi I''m a C# .NET newbie doing a minor school project but I''m getting a
strange error message.

''System.NullReferenceException'' occurred in system.windows.forms.dll
Additional information: Object reference not set to an instance of an
object."

As my references look I seem to be using the old framework(1.0.3705) for
this, but re-referencing to the newer framework(1.1.4322) dll''s produces the
same error. This happens under all circumstances when I''m trying to compile
a fully managed project. Even from scratch when trying to just compile the
empty form this happens.

If you read the old thread I''ve included you can see that he changed his
sourcepath for the whole project to something that is not put in the
MyDocuments folders. I did exactly the same thing and it worked, the
question from me is WHY? All other apps (so far) compiles flawless, it''s
only these C# Windows Applications Projects that fail.

Regards,

Andreas Wirén

OS : Windows XP Professional SP1 with all the recent hotfixes and updates.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{

}
}
}

http://groups.google.se/groups?hl=sv...3D%2522Applica
tion.Run(new%2BForm1())%253B%2522%2B%2522object%2B reference%2Bnot%2Bset%2522
%26hl%3Dsv%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3D6FADa.54216%2524g33.74
9173%2540weber.videotron.net%26rnum%3D6

推荐答案

Andreas,

你可以使用非创建的对象。

例如


MyClass myobject;

myobject.MyMethod();

- 错误;


你应该这样做:


MyClass myobject;

myobject = new MyClass( );

myobject.MyMethod();


"AndreasWirén" <一个***** @ clan.dcs.se> ó???Yéì/ó???Yéìá×??×?ó??èóì????Y ??:

新闻:HB *********** ********* @ newsc.telia.net ...
Andreas,
You may use non created object.
for example

MyClass myobject;
myobject.MyMethod();
-- error;

You shoul do:

MyClass myobject;
myobject = new MyClass();
myobject.MyMethod();

"Andreas Wirén" <an*****@clan.dcs.se> ó???Yéì/ó???Yéìá × ??×?ó??è óì???àY??:
news:HB********************@newsc.telia.net...
你好我是C#.NET新手做一个小型学校项目但是我得到了一个奇怪的错误信息。

'System.NullReferenceException''发生在system.windows.forms.dll
附加信息:对象引用未设置为
对象的实例。

正如我的参考文献看起来我似乎在使用旧框架(1.0.3705)这个,但重新引用更新的框架(1.1.4322)dll'产生
同样的错误。在我尝试
编译完全托管项目的所有情况下都会发生这种情况。即使从头开始尝试只编译空表格也会发生这种情况。

如果您阅读我已经包含的旧主题,您可以看到他更改了他的
源路径整个项目是没有放在
MyDocuments文件夹中的东西。我做了完全相同的事情并且有效,我的问题是为什么?所有其他应用程序(到目前为止)编译完美无瑕,只有这些C#Windows应用程序项目失败。

问候,

AndreasWirén
操作系统:Windows XP Professional SP1,包含所有最新的修补程序和更新。

使用System;
使用System.Drawing;
使用System.Collections;
使用System.ComponentModel;
使用System.Windows.Forms;
使用System.Data;

命名空间WindowsApplication1
{
///< ;摘要>
/// Form1的摘要说明。
///< / summary>
公共类Form1:System.Windows.Forms.Form
{
///< summary>
///所需的设计变量。
///< / summary>
私有System.ComponentModel.Container components = null;
<公共Form1()
{
//
// Windows窗体设计器支持需要
//
InitializeComponent();

//
// TODO:添加任何con InitializeComponent调用后的结构代码
//
}
///< summary>
///清理正在使用的所有资源。
/ //< / summary>
protected override void Dispose(bool disposing)
{
if(disposing)
{
if(components!= null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}

#region Windows表单设计器生成的代码
///< summary>
///支持Designer的必需方法 - 不要使用代码编辑器修改此方法的内容。
///< / summary>
private void InitializeComponent()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5,13);
this.ClientSize = new System.Drawing.Size(292,266);
this.Name =" Form1";
this.Text =" Form1";
this.Load + = new System.EventHandler(this.Form1_Load);

}
#endregion

///< summary>
///主要切入点对于应用程序。
///< / summary>
[STAThread]
static void Main()
{/> Application.Run(new Form1()) ;
}

private void Form1_Load(object sender,System.EventArgs e)
{

}
}
}

http://groups.google.se/groups?hl = sv ... 3D%2522Applica
tion.Run(new%2BForm1())%253B%2522%2B%2522object%2B reference%2Bnot%2Bset%2522
%26hl% 3Dsv%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3D6FADa.54216%2524g33.74 9173%2540weber.videotron.net%26rnum%3D6
Hi I''m a C# .NET newbie doing a minor school project but I''m getting a
strange error message.

''System.NullReferenceException'' occurred in system.windows.forms.dll
Additional information: Object reference not set to an instance of an
object."

As my references look I seem to be using the old framework(1.0.3705) for
this, but re-referencing to the newer framework(1.1.4322) dll''s produces the same error. This happens under all circumstances when I''m trying to compile a fully managed project. Even from scratch when trying to just compile the
empty form this happens.

If you read the old thread I''ve included you can see that he changed his
sourcepath for the whole project to something that is not put in the
MyDocuments folders. I did exactly the same thing and it worked, the
question from me is WHY? All other apps (so far) compiles flawless, it''s
only these C# Windows Applications Projects that fail.

Regards,

Andreas Wirén

OS : Windows XP Professional SP1 with all the recent hotfixes and updates.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);

}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{

}
}
}

http://groups.google.se/groups?hl=sv...3D%2522Applica tion.Run(new%2BForm1())%253B%2522%2B%2522object%2B reference%2Bnot%2Bset%2522 %26hl%3Dsv%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26selm%3D6FADa.54216%2524g33.74 9173%2540weber.videotron.net%26rnum%3D6



Dmitry Karneyev< ka ****** @ msn.com> ;写道:
Dmitry Karneyev <ka******@msn.com> wrote:
Andreas,
你可以使用非创建的对象。


MyClass myobject;
myobject.MyMethod();
- 错误;

你应该这样做:

MyClass myobject;
myobject = new MyClass();
myobject.MyMethod( );
Andreas,
You may use non created object.
for example

MyClass myobject;
myobject.MyMethod();
-- error;

You shoul do:

MyClass myobject;
myobject = new MyClass();
myobject.MyMethod();




但这并不是这里发生的事情。代码编译并运行正常。

请注意,根据消息,错误发生在

编译期间,而不是在运行时。


-

Jon Skeet - < sk *** @ pobox.com>
http://www.pobox.com/~skeet

如果回复小组,请不要给我发邮件



But that''s not what''s happening here. The code compiles and runs fine.
Note that according to the message, the error occurs during
compilation, not at runtime.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


它似乎从system.windows.forms.dll中给出NullReferenceException


如果使用Visual Studio 2002,则不能使用v1。 1.


我会尝试重新安装框架。


-

使用M2,Opera革命性的电子邮件客户端: http://www.opera.com/m2/
It appears to give a NullReferenceException from system.windows.forms.dll

If you use Visual Studio 2002 you can''t use v1.1.

I''d try to reinstall the framework.

--
Using M2, Opera''s revolutionary e-mail client: http://www.opera.com/m2/


这篇关于System.NullReferenceException发生在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆