Label[] label = new Label[12];
public light()
{
InitializeComponent();
label[0].Location = new Point(120, 150);
label[1].Location = new Point(138, 150);
label[2].Location = new Point(156, 150);
label[3].Location = new Point(174, 150);
label[4].Location = new Point(174, 132);
label[5].Location = new Point(174, 114);
label[6].Location = new Point(174, 96);
label[7].Location = new Point(156, 96);
label[8].Location = new Point(138, 96);
label[9].Location = new Point(120, 96);
label[10].Location = new Point(120, 114);
label[11].Location = new Point(120, 132);
for (int i = 0; i < label.Length;i++ )
{
label[i].Size = new Size(16, 16);
label[i].BackColor = Color.Blue;
label[i].Text = "";
panel1.Controls.Add(label[i]);
}
}其中的Label[] label = new Label[12];
是类中字段声明,light()是构造函数,整个程序运行之后没有出现界面,调试时单步运行完label[0].Location = new Point(120, 150);这句代码后就出现异常,说“未将对象引用设置到对象的实例。”这是何解?
public light()
{
InitializeComponent();
label[0].Location = new Point(120, 150);
label[1].Location = new Point(138, 150);
label[2].Location = new Point(156, 150);
label[3].Location = new Point(174, 150);
label[4].Location = new Point(174, 132);
label[5].Location = new Point(174, 114);
label[6].Location = new Point(174, 96);
label[7].Location = new Point(156, 96);
label[8].Location = new Point(138, 96);
label[9].Location = new Point(120, 96);
label[10].Location = new Point(120, 114);
label[11].Location = new Point(120, 132);
for (int i = 0; i < label.Length;i++ )
{
label[i].Size = new Size(16, 16);
label[i].BackColor = Color.Blue;
label[i].Text = "";
panel1.Controls.Add(label[i]);
}
}其中的Label[] label = new Label[12];
是类中字段声明,light()是构造函数,整个程序运行之后没有出现界面,调试时单步运行完label[0].Location = new Point(120, 150);这句代码后就出现异常,说“未将对象引用设置到对象的实例。”这是何解?
解决方案 »
- 求人!我知道要谦卑!!!但我想骂娘!!!
- 一个在线转换应用,Word转CHM 在线转换
- 数组长度到底能定义多大?能超过1G吗?
- winform线程修改界面上的显示问题
- UDPCLIENT的问题:通常每个套接字地址(协议/网络地址/端口)只允许使用一次
- dataGrid
- MDI的问题!急!~
- 高手求救,怎样让一个窗口最前,而且其他窗口无法操作,只有当前窗口关闭后其他窗口才能操作
- OA系统中,直接下载服务器上的文件(如WORD)到本地计算机的方法
- 请问可以在remoting 中客户端调用服务端方法时,传一个对象数组到服务端的方法里啊?怎么解决?谢谢!!!
- c# gethdc() 溢出 求解
- 请问,如何检查DataTable的主键错误
加 label[0]=new Label();
label[0].Location = new Point(120, 150);
没有初始化,只是声明而已。public light()
{
InitializeComponent();
label[0] = new Label();
label[0].Location = new Point(120, 150);
label[1] = new Label();
label[1].Location = new Point(138, 150);
}另一句,写代码的方式我不提,只说一点,学会自己调试,别只会把错误信息读出来。编译器做了那么强大的调试功能你却连最简单的使用的不会,这真是一种悲哀,你所看的错误信息一个丝毫不懂编程的人一样可以读到。
//Label[] label = new Label[12];
//省略前面
//InitializeComponent();
for (int i = 0; i < label.Length; i++)
{
label[i] = new Label();
}
//省略后面