【发布时间】:2012-08-12 02:38:02
【问题描述】:
我收到这个空引用错误
private int Cont;
private List<string> myStrings;
private ArrayList str;
private string[] strs;
myclass()
{
Cont = 0;
myStrings = new List<string>();
str = new ArrayList();
strs =new string[27];
for(int i = 0; i < 27;i++)
{
strs[i] = "";
}
}
public void AddTexture(string name)
{
Console.WriteLine("Count "+Cont);
Console.WriteLine("ive got the texture "+name);
myStrings.Add(name);
//strs[Cont] = name;
//str.Add(name);
Cont++;
}
如您所见,我已经尝试使用列表、数组列表和数组,但当我尝试添加第一个值时,它们都不起作用= 0 在第一个写入行
知道我做错了什么吗?谢谢你 错误是每当我试图填充数组、数组列表或列表时 在 2 console.writeline 之后的函数 AddTexture 中,我评论了这两行,但那是因为这些是我尝试使用数组、数组列表和列表的方式
【问题讨论】:
-
每当我尝试填充数组或数组列表或列表时
-
在console.writelines之后的函数addtexture
-
几乎所有的 NullReferenceException 情况都是一样的。请参阅“What is a NullReferenceException in .NET?”获取一些提示。
-
何时何地调用 AddTexture?
-
@Habib - 我假设它已声明但未初始化。
标签: c# arrays list arraylist nullreferenceexception