下面两个事件为什么有NullPointerException异常?具体源程序在附件中,这是用JBUILDER2005开发的!
public void jButton1_actionPerformed(ActionEvent e) {
try{
int i=Integer.parseInt(item);
int m = xuan[i].size();
for(int k=1;k<=m;k++)
{
String row[]={String.valueOf(k),(String)nameda.elementAt(i),(String)xuan[i].elementAt(k)};
model.addRow(row);
}
}catch(NullPointerException ee){System.out.print(ee);}
}
public void jComboBox1_actionPerformed(ActionEvent e) {
try {
item = (String) jComboBox1.getSelectedItem();
int i = Integer.parseInt(item);
jTextArea1.setText((String) nameda.elementAt(i));
} catch (ArrayIndexOutOfBoundsException ee) {
System.out.print(ee);
}
}
----------------解决方案--------------------------------------------------------
详细代码见附件
----------------解决方案--------------------------------------------------------
空指针异常是最好排的异常
你只要确保每个对象都不为空的时候,就不会了
----------------解决方案--------------------------------------------------------