c**t 发帖数: 26 | 1 public class myclass
{
private String [] typeId=null;
public myclass(){};
public String [] getTypeId(Res a)
{
int i=0;
for(i=0;i
{
if(a[i]!=null)
{
typeId[i]=new String("Levl " + i);
}
}
return typeId;
}
}
调用getTypeId时的a不是空的,但getTypeId返回时出错,说是NullPointerExceptio |
c**t 发帖数: 26 | 2 即使把getTypeId写成下面这样,还是返回空
public String [] getTypeId()
{
typeId[0]="I";
typeId[1]="2";
return typeId;
}
【在 c**t 的大作中提到】 : public class myclass : { : private String [] typeId=null; : public myclass(){}; : public String [] getTypeId(Res a) : { : int i=0; : for(i=0;i: { : if(a[i]!=null)
|
P****y 发帖数: 707 | 3 need initiate the size of the string array?
【在 c**t 的大作中提到】 : public class myclass : { : private String [] typeId=null; : public myclass(){}; : public String [] getTypeId(Res a) : { : int i=0; : for(i=0;i: { : if(a[i]!=null)
|
c**t 发帖数: 26 | 4 可size是变的呀,决定于a.length
【在 P****y 的大作中提到】 : need initiate the size of the string array?
|
z****g 发帖数: 2497 | 5 Didn't initializee typeId array.
Modification below:
/// Init typeId
typeId = new String[a.length];
// BTW, what is Res? can it call a.length?
【在 c**t 的大作中提到】 : public class myclass : { : private String [] typeId=null; : public myclass(){}; : public String [] getTypeId(Res a) : { : int i=0; : for(i=0;i: { : if(a[i]!=null)
|