首先我定义两个类,虽然这两个类不是太规范我觉得还是能用的
public class TPoint
{
public int x;
public int y;
public int z;
public TPoint()
{
x = 0;
y = 0;
z = 0;
}
public TPoint(int a, int b, int c)
{
x = a;
y = b;
z = c;
}
}
public class Surface
{
public List<TPoint> Simppoint = new List<TPoint>();
public Surface()
{
}
}
然后我从一个txt 文档你们读取数据
里面数据类似 12 45 1
22 88 1
………………….
class Doc
{
public Surface[] surface = new Surface[100];
public int number;
public Doc()
{
FileStream fs = new FileStream(@”D:\a.txt”, FileMode.Open);
StreamReader sr = new StreamReader(fs);
string tpoint;
int i = 0;
int N;
while ((tpoint = sr.ReadLine()) != null)
{
TPoint tp = new TPoint();
for (i = 0; tpoint[i] != “” “”; i++)
{
tp.x = tp.x * 10 + tpoint[i] – “”0″”;
//surface[N].point[surface[N].length].x=surface[N].point[surface[N].length].x*10+(tpoint[i]-“”0″”);
}
for (i++; tpoint[i] == “” “”; i++)
{
}
for (; tpoint[i] != “” “”; i++)
{
tp.y = tp.y * 10 + tpoint[i] – “”0″”;
//surface[N].point[surface[N].length].y=surface[N].point[surface[N].length].y*10+(tpoint[i]-“”0″”);
}
for (i++; tpoint[i] == “” “”; i++)
{
}
for (; i < tpoint.Length; i++)
{
tp.z = tp.z * 10 + tpoint[i] – “”0″”;
//surface[N].point[surface[N].length].z=surface[N].point[surface[N].length].z*10+(tpoint[i]-“”0″”);
}
N = tp.z;
surface[N].Simppoint.Add(tp);//每次程序运行到这里就发生中断异常
number = N;
}
sr.Close();
}
每次程序运行到这里就发生中断异常 surface[N].Simppoint.Add(tp);+ 已引发:“未将对象引用设置到对象的实例。”(System.NullReferenceException) 异常消息 = “未将对象引用设置到对象的实例。”, 异常类型 = “System.NullReferenceException”, 异常 WinRT 数据 = “”
真心很急,求大神指教