求助 C#程序异常 "处理NullReferenceException"

icbc_ljt 2008-04-19 10:18:53
显示:"处理NullReferenceException
未将对象引用设置到对象的实例"

以下这段程序变为黄色: "string[] strContent = FileContent.Split();"

以下为程序中的一段,请各住指教下:
//鼠标响应方法
private void HelloWorld_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
ArrayList listContent = new ArrayList();
//将FileContent按照空格或者制表符分割成字符串数组
string[] strContent = FileContent.Split();
foreach (string str in strContent)
{
if (str != "")
{
listContent.Add(str);
}
}
string strDislpay = "";
foreach (object obj in listContent)
{
string str = obj as string;//obj转换为string类型
if (str != null)
{
strDislpay += str + System.Environment.NewLine;//????????????????????
}
MessageBox.Show(strDislpay);
}
}
...全文
383 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
icbc_ljt 2008-04-20
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 dancingbit 的回复:]
你只定义了这个字符串类型的变量,并没有给它赋值,当然就是null了。
[/Quote]
嗯,原来这样
liqngjun123 2008-04-19
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 dancingbit 的回复:]
你只定义了这个字符串类型的变量,并没有给它赋值,当然就是null了。
[/Quote]
dancingbit 2008-04-19
  • 打赏
  • 举报
回复
你只定义了这个字符串类型的变量,并没有给它赋值,当然就是null了。
icbc_ljt 2008-04-19
  • 打赏
  • 举报
回复
不是的,
private string FileContent; //文件内容
FileContent是文件内容
jinjazz 2008-04-19
  • 打赏
  • 举报
回复
FileContent是不是null

110,566

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧