2017-01-21 80 views
-1

我想定義保利坤陣列,所以:陣列多邊形

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 ... 由於任何幫助...

回答

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"); 
}