编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛  
全能 ASP / PHP / ASP.NET 主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付学习型 ASP/PHP/ASP.NET 主机 30元/年
发新话题
打印

“System.NullReferenceException

“System.NullReferenceException

代码好像没什么问题,运行时就是这样的提示
我是初学者,现在还是一头雾水呢
谢谢大家帮忙 阿

TOP

未处理的“System.NullReferenceException”类型的异常出现在 WindowsApplication6.exe 中。

其他信息: 未将对象引用设置到对象的实例。

TOP

以后写东西要尽量的详细,在一次重申,大家记得啊
我相信我的付出

TOP

你可以把你的程序放上来给其他人看一下是什么问题的啊!

TOP

可以用MSDN具体查一下是什么原因。
或者对有问题的语句用
try
{
    //Statements
}
catch(Exception err)
{
    Console.WriteLine("{0}", err.Message);
}
察看稍微具体一点的错误原因
喝杯汽酒,交个朋友

TOP

private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); this.textBox2 = new System.Windows.Forms.TextBox(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.button1 = new System.Windows.Forms.Button(); this.SuspendLayout(); // // label1 // this.label1.Location = new System.Drawing.Point(8, 40); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(64, 16); this.label1.TabIndex = 0; this.label1.Text = "学号"; // // textBox2 // this.textBox2.Location = new System.Drawing.Point(88, 40); this.textBox2.Name = "textBox2"; this.textBox2.Size = new System.Drawing.Size(104, 21); this.textBox2.TabIndex = 1; this.textBox2.Text = ""; // // groupBox1 // this.groupBox1.Location = new System.Drawing.Point(48, 104); this.groupBox1.Name = "groupBox1"; this.groupBox1.Size = new System.Drawing.Size(192, 120); this.groupBox1.TabIndex = 2; this.groupBox1.TabStop = false; this.groupBox1.Text = "frm"; // // button1 // this.button1.Location = new System.Drawing.Point(104, 80); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(80, 16); this.button1.TabIndex = 3; this.button1.Text = "click me!"; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(292, 333); this.Controls.Add(this.button1); this.Controls.Add(this.groupBox1); this.Controls.Add(this.textBox2); this.Controls.Add(this.label1); this.Name = "Form1"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Load += new System.EventHandler(this.Form1_Load); this.ResumeLayout(false);

}

static int Main(string[] args) { Application.Run(new Form1()); return 0; }

private void button1_Click(object sender, EventArgs evargs) { //textBox2.Text ="click me!"; MessageBox.Show ("hello"); }

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

未处理的“System.NullReferenceException”类型的异常出现在 WindowsApplication6.exe 中。其他信息: 未将对象引用设置到对象的实例。

TOP

你是对一个参考类型的变量进行了操作,然而这个参考变量仅仅是声明了,却没有给它定义一个值,也就是说,那个变量还是null,你就对它进行操作,这样就会导致这个异常
像这样:
class a
{
int x,y;
}
...
a  aaa;//仅仅是声明了
aaa.x=10;//这个地方就会出现那样的异常,因为aaa仅仅是声明了,还没有值,还是null

aaa=new a();//为aaa建立内存实体
a.x=10;//OK
寻求挑战,追求完美 Oh,my god!

TOP

发新话题