未将对象引用设置到对象的实例。

zsj752144492 2012-05-27 11:23:08
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Exp1
{
class treeNode
{
string attribute;

public string Attribute
{
get { return attribute; }
set { attribute = value; }
}
List<string> valueofAttr;

public List<string> ValueofAttr
{
get { return valueofAttr; }
set { valueofAttr = value; }
}
treeNode parent;

internal treeNode Parent
{
get { return parent; }
set { parent = value; }
}
public List<treeNode> child;

//internal List<treeNode> Child
//{
// get { return child; }
// set { child = value; }
//}
string parent_attr_value;

public string Parent_attr_value
{
get { return parent_attr_value; }
set { parent_attr_value = value; }
}

string yesorno;

public string Yesorno
{
get { return yesorno; }
set { yesorno = value; }
}

public void addChild(treeNode n) {
this.child.Add(n); 这里提示“未将对象引用设置到对象的实例。”
}

public treeNode(string attribute) {
this.attribute = attribute;
this.child = null;
this.parent = null;
this.parent_attr_value = null;
this.valueofAttr = null;
this.yesorno = null;
}
}
}

treeNode n = new treeNode(root.Attribute);
n.Parent = root;
n.Parent_attr_value = s;
n.Yesorno = temp.First().PlayBall.ToString();
//List<treeNode> hg = new List<treeNode>();
//hg = root.child;
//hg.Add(n);
root.addChild(n);
...全文
76 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
言多必失 2012-05-27
  • 打赏
  • 举报
回复
public void addChild(treeNode n) {
if(child!=null)
this.child.Add(n); 这里提示“未将对象引用设置到对象的实例。”
}

ParanoidKing 2012-05-27
  • 打赏
  • 举报
回复
构造方法设this.child = null;后一直都没有实例化,直接调Add方法当然会出错啊。

111,126

社区成员

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

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

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