我想定义Poly gon Array,所以:
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 ... 感谢任何帮助...
答案 0 :(得分:1)
你必须初始化数组的对象:
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");
}