以下代码抛出 NullPointerException - 我不知道问题出在哪里。我使用 Excel 电子表格作为后端。
//actionlistener for btnfetch
btnfetch.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ae)
{
try
{
String name="";
d1 = (java.util.Date)formatter.parse(textdate.getText());
java.sql.Date sqlDate = new java.sql.Date(d1.getTime());
java.sql.Date sqld=null;
ResultSet rs=st.executeQuery("select * from [ARNUM$]");
String getname=null;
while(rs.next())
{
getname=rs.getString(1);
sqld=rs.getDate(2);
System.out.println(getname+" "+sqld+" "+sqlDate);
if(sqlDate.compareTo(sqld)==0)
{
name=name+" "+getname;
name=name.toUpperCase();
}
System.out.println(name);
}
if(name.length()==0)
{
JOptionPane.showMessageDialog(
pnlp4,
"No Name having "+textdate.getText(),
"Warning",
JOptionPane.WARNING_MESSAGE
);
}
else
{
textname.setText(name);
}
}
catch(Exception e)
{
e.printStackTrace();
}
}//end actionPerformed
}); //end addActionListener