我搜索过这个错误,但那些并没有解决我的问题。
字段是,JTextfield为:
private java.util.List<JTextField> field;
我的功能如下:
public static bank addDebt( double payment ) {
return new bank( 1, payment );
}
我正在调用它,这一行给了我错误:
bank.addDebt( Double.parseDouble( field.get(9).getText() ) );
但是这给了我:
double无法解除引用
代码的一部分:
private class listener implements ActionListener{
@Override public void actionPerformed( ActionEvent e ){
JButton clicked = (JButton)e.getSource();
if( clicked == button.get(0) ){
try {
PreparedStatement st = connect.prepareStatement("select * from caridata where code=?");
st.setString(1, field.get(0).getText() );
ResultSet rs = st.executeQuery();
while( rs.next() ){
//debt = rs.getDouble( "debt" );
//owe = rs.getDouble( "owe" );
//bank = rs.getDouble( "bank" );
for( int i=0;i<field.size();i++ ){
if( i == 1 )
field.get(i).setText( rs.getString( i+1 ) );
else if( i == 9 || i == 10 || i == 11 )
field.get(i).setText( Double.toString( rs.getDouble( i+1 ) ) );
else
field.get(i).setText( rs.getString( i+1 ) );
}
}
//
} catch (Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(null,"Error Code = 0005");
}
}else if( clicked == button.get(1) ){
final JFileChooser fileDialog = new JFileChooser();
int returnVal = fileDialog.showOpenDialog( frame );
if( returnVal == JFileChooser.APPROVE_OPTION ){
java.io.File file = fileDialog.getSelectedFile( );
field.get(14).setText( file.getPath() );
}
}else if( clicked == button.get(2) ){
try {
PreparedStatement st = connect.prepareStatement("update caridata set code=?,enterdate=?,by=?,itgroup=?,fullname=?,email=?,gsm=?,web=?,fax=?,debt=?,owe=?,bank=?,info=?,explain=?,image=? where code=?");
for( int i=0;i<field.size();i++ ){
if( i == 1 )
st.setDate( i+1, java.sql.Date.valueOf( field.get(i).getText() ) );
else if( i == 9 || i == 10 || i == 11 )
st.setDouble( i+1, Double.parseDouble( field.get(i).getText() ) );
else
st.setString( i+1, field.get(i).getText() );
}
st.setString(16, field.get(0).getText());
st.executeUpdate();
//bank.rmvDebt( debt );
//bank.rmvPayment( owe );
//bank.rmvTotal( bank );
//bank.addDebt( Double.parseDouble( field.get(9).getText() ) );
//bank.addPayment( Double.parseDouble( field.get(10).getText() ) );
//bank.addTotal( Double.parseDouble( field.get(11).getText() ) );
JOptionPane.showMessageDialog(null,"It's done");
} catch (Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(null,"Error Code = 0006");
} finally {
bank.addDebt( field.get(9).getText() );
bank.addPayment( field.get(10).getText() );
bank.addTotal( field.get(11).getText() );
}
}else if( clicked == button.get(3) ){
for( int i=0;i<field.size();i++ )
field.get(i).setText("");
}
}// action
}// listener
}
整个
/bank.rmvDebt( debt );
//bank.rmvPayment( owe );
//bank.rmvTotal( bank );
//bank.addDebt( Double.parseDouble( field.get(9).getText() ) );
//bank.addPayment( Double.parseDouble( field.get(10).getText() ) );
赋予双倍无法解除引用。
我一直在其他文件中这样做,但这次发生了一些事情,我不知道它是什么。我错过了什么?
答案 0 :(得分:3)
这看起来很可疑:
//bank = rs.getDouble( "bank" );
如果在某些时候没有评论,则表示您有一个名为double
的{{1}}变量,可能会隐藏您的bank
课程。这可以解释你得到的错误,因为bank
无法解除引用(即double
无效)。