2016-09-28 95 views
1
private String[] items; 
private int numItems; 

public SortedListArrayBased() 
{ 
    items = null; 
    numItems = 0; 
} 

這是我的構造函數創建一個數組,但在接下來的方法我想在它創建值的數組像這樣在另一種方法

if(numItems == 0) 
{ 
    items[0] = temp; 
    numItems++; 
} 

當我運行,它告訴我空指針,我認爲是因爲數組沒有從構造函數中的空間,有沒有辦法在第二種方法重新初始化我的數組。謝謝。

回答

0

變化

public SortedListArrayBased() 
{ 
    items = null; 
    numItems = 0; 
} 

public SortedListArrayBased() 
{ 
    items = new String[];; 
    numItems = 0; 
} 
相關問題