相关代码如下,运行时提示“allpersontable.setValueAt(allperson[count].getID(),count+1,count+0);”这行抛出了那个异常,我想了一下,应该是allperson这个对象数组的问题,可是我明明已经对它进行复制了啊,为什么还会出现那个异常呢?请指教。不胜感激:
if(idtextfield.getText().equals("*"))
{
JFrame resultframe=new JFrame("密码管理器");
setIconImage(getToolkit().getImage("C:\\Users\\lenovo\\Desktop\\信息管理器\\login.jpg"));
Person allperson[]=adddeleteupdateselect.selectAll();
JTable allpersontable=new JTable(allperson.length,5);
allpersontable.setValueAt("ID",0,0);
allpersontable.setValueAt("Name", 0,1);
allpersontable.setValueAt("Password", 0,2);
allpersontable.setValueAt("Age", 0,3);
allpersontable.setValueAt("Email",0,4);
for(int count=0;count<allperson.length;count++)
{
allpersontable.setValueAt(allperson[count].getID(),count+1,count+0);
allpersontable.setValueAt(allperson[count].getName(),count+1,count+1);
allpersontable.setValueAt(allperson[count].getPassword(),count+1,count+2);
allpersontable.setValueAt(allperson[count].getAge(),count+1,count+3);
allpersontable.setValueAt(allperson[count].getEmail(),count+1,count+4);
//what will happen if the email is null?
}
allpersontable.setBounds(0,0,500,400);
resultframe.add(new JScrollPane(allpersontable));
resultframe.setSize(500,250);
resultframe.setVisible(true);
resultframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
其中selectAll方法的代码为:
public Person[] selectAll()
{
String sql="select * from INFORMATION";
PreparedStatement preparedstatement=null;
Person allpersonlist[]=new Person[100];
try
{
preparedstatement=connection.getconnection().prepareStatement(sql);
ResultSet allperson=preparedstatement.executeQuery();
while(allperson.next())
{
int i=0;
allpersonlist[i].setID(allperson.getString(allperson.getRow()));
allpersonlist[i].setName(allperson.getString(allperson.getRow()));
allpersonlist[i].setPassword(allperson.getString(allperson.getRow()));
allpersonlist[i].setAge(allperson.getInt(allperson.getRow()));
allpersonlist[i].setEmail(allperson.getString(allperson.getRow()));
i++;
}
allperson.close();
preparedstatement.close();
}
catch(SQLException e)
{
System.out.println("查询全部人物时出现错误");
}
finally
{
return allpersonlist;
}
}
------解决思路----------------------
去查下数据库INFORMATION表是不是每一行每一列都有数据。。