2016-09-28 94 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; 
}