多边形阵列
Array of Polygons
我想定义多边形数组,所以:
private static ArrayList<PolyDefault> basePolyList = new ArrayList<PolyDefault>();
//read the file and store to basePolyList
parser.readBaseFile(filename_1, basePolyList);
//get size of basePolyList
int SizeOfBase = basePolyList.size();
//def Array of polygon
Poly[] p4=new PolyDefault[SizeOfBase];
for(int i=0;i<SizeOfBase;i++)
{
p4[0].add(basePolyList.get(i));
System.out.println("Poly of Base["+i+"]"+" has " +p4[i].getNumPoints()+"\n");
}
但是我有这个错误:
线程异常 "main" java.lang.NullPointerException ...
感谢任何帮助...
你必须初始化数组的对象:
for(int i=0;i<SizeOfBase;i++)
{
p4[i] = new Poly();
p4[i].add(basePolyList.get(i));
System.out.println("Poly of Base["+i+"]"+" has " +p4[i].getNumPoints()+"\n");
}
我想定义多边形数组,所以:
private static ArrayList<PolyDefault> basePolyList = new ArrayList<PolyDefault>();
//read the file and store to basePolyList
parser.readBaseFile(filename_1, basePolyList);
//get size of basePolyList
int SizeOfBase = basePolyList.size();
//def Array of polygon
Poly[] p4=new PolyDefault[SizeOfBase];
for(int i=0;i<SizeOfBase;i++)
{
p4[0].add(basePolyList.get(i));
System.out.println("Poly of Base["+i+"]"+" has " +p4[i].getNumPoints()+"\n");
}
但是我有这个错误: 线程异常 "main" java.lang.NullPointerException ... 感谢任何帮助...
你必须初始化数组的对象:
for(int i=0;i<SizeOfBase;i++)
{
p4[i] = new Poly();
p4[i].add(basePolyList.get(i));
System.out.println("Poly of Base["+i+"]"+" has " +p4[i].getNumPoints()+"\n");
}