C#程序问题:未处理 System.NullReferenceException Message未将对象引用设置到对象的实例
usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingSystem.Windows.Forms;names...
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class FrmShow : Form
{
public SE[] engineers = new SE[3];
public FrmShow()
{
InitializeComponent();
}
private void BindLV() //绑定ListView控件
{
lVAssess.Items.Clear();
engineers[0].ID = "段长权";
engineers[0].Name = "段长权";
engineers[0].Age = "段长权";
engineers[0].Score = "段长权";
engineers[0].Assess = "段长权";
engineers[1].ID = "段长权";
engineers[1].Name = "段长权";
engineers[1].Age = "段长权";
engineers[1].Score= "段长权";
engineers[1].Assess= "段长权";
engineers[2].ID = "段长权";
engineers[2].Name = "段长权";
engineers[2].Age = "段长权";
engineers[2].Score = "段长权";
engineers[2].Assess= "段长权";
for (int i = 0; i < engineers.Length; i++)
{
ListViewItem item = new ListViewItem();
item.Text = engineers[i].ID;
item.SubItems.Add(engineers[i].Name = "段长权");
item.SubItems.Add(engineers[i].Age = "18");
item.SubItems.Add(engineers[i].Score = "100");
item.SubItems.Add(engineers[i].Assess = "很好");
lVAssess.Items.Add(item);
}
}
这是一个WindowsForm窗体应用程序,使用数组的方式循环往ListView控件里面添加数据
谁知道哪儿有问题? 展开
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class FrmShow : Form
{
public SE[] engineers = new SE[3];
public FrmShow()
{
InitializeComponent();
}
private void BindLV() //绑定ListView控件
{
lVAssess.Items.Clear();
engineers[0].ID = "段长权";
engineers[0].Name = "段长权";
engineers[0].Age = "段长权";
engineers[0].Score = "段长权";
engineers[0].Assess = "段长权";
engineers[1].ID = "段长权";
engineers[1].Name = "段长权";
engineers[1].Age = "段长权";
engineers[1].Score= "段长权";
engineers[1].Assess= "段长权";
engineers[2].ID = "段长权";
engineers[2].Name = "段长权";
engineers[2].Age = "段长权";
engineers[2].Score = "段长权";
engineers[2].Assess= "段长权";
for (int i = 0; i < engineers.Length; i++)
{
ListViewItem item = new ListViewItem();
item.Text = engineers[i].ID;
item.SubItems.Add(engineers[i].Name = "段长权");
item.SubItems.Add(engineers[i].Age = "18");
item.SubItems.Add(engineers[i].Score = "100");
item.SubItems.Add(engineers[i].Assess = "很好");
lVAssess.Items.Add(item);
}
}
这是一个WindowsForm窗体应用程序,使用数组的方式循环往ListView控件里面添加数据
谁知道哪儿有问题? 展开
3个回答
展开全部
public SE[] engineers = new SE[3];
你只实例化了一个数组,但是数组里面的内容都是为null,
所以在 engineers[0].ID = "段长权";这里就会报空引用的错误。
public SE[] engineers = new SE[3];
for(int intX = 0; intX < engineers.length; intX++)
{
engineers[intX] = new se();
}
这样就可以了。
你只实例化了一个数组,但是数组里面的内容都是为null,
所以在 engineers[0].ID = "段长权";这里就会报空引用的错误。
public SE[] engineers = new SE[3];
for(int intX = 0; intX < engineers.length; intX++)
{
engineers[intX] = new se();
}
这样就可以了。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
空引用,有变量为空,但仍然访问了它的属性或者方法,和楼上的意见一样
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询