正在用JBuilder2005做一个J2ME软件.
下面代码运行是成功的.
ButtonSP btn1=new ButtonSP("ZZ","1111");
ButtonSP btn2=new ButtonSP("XX","2222");
ButtonSP btn3=new ButtonSP("YY","3333");
mainForm.append(btn1);
mainForm.append(btn2);
mainForm.append(btn3);
其中ButtonSP是一个按钮类.
因为种种原因,开始时并不知道按钮有多少个,故写成下面数组形式(测试用):
public String[] strPassword={"11","22","33"};
public String[] strName={"AA","BB","CC"};
public ButtonSP[] btn;
for (int i=1;i<strPassword.length-1;i++)
{
btn[i]=new ButtonSP(strName[i],strPassword[i]);
mainForm.append(btn[i]) ;
}
运行出现java.lang.NullPointerException.
请问诸位大侠何策解之?谢谢
下面代码运行是成功的.
ButtonSP btn1=new ButtonSP("ZZ","1111");
ButtonSP btn2=new ButtonSP("XX","2222");
ButtonSP btn3=new ButtonSP("YY","3333");
mainForm.append(btn1);
mainForm.append(btn2);
mainForm.append(btn3);
其中ButtonSP是一个按钮类.
因为种种原因,开始时并不知道按钮有多少个,故写成下面数组形式(测试用):
public String[] strPassword={"11","22","33"};
public String[] strName={"AA","BB","CC"};
public ButtonSP[] btn;
for (int i=1;i<strPassword.length-1;i++)
{
btn[i]=new ButtonSP(strName[i],strPassword[i]);
mainForm.append(btn[i]) ;
}
运行出现java.lang.NullPointerException.
请问诸位大侠何策解之?谢谢