Redian新闻
>
怎么返回空指针呢?
avatar
怎么返回空指针呢?# Java - 爪哇娇娃
c*t
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
avatar
c*t
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)

avatar
P*y
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)

avatar
c*t
4
可size是变的呀,决定于a.length

【在 P****y 的大作中提到】
: need initiate the size of the string array?
avatar
z*g
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)

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。