{{1}}
答案 0 :(得分:1)
您必须添加if条件并从try块中抛出异常。 请参阅http://beginnersbook.com/2013/04/throw-in-java/以获取进一步的参考资料
答案 1 :(得分:0)
这里是更新我的代码也有一个异常在try之外我在try中移动了行声明并且问题解决了谢谢你。
private void table_Order_EKeyPressed(java.awt.event.KeyEvent evt) {
try{
int row = table_Order_E.getSelectedRow();//the exception may be here.
if (row >=0 && evt.getKeyCode() == KeyEvent.VK_INSERT) {
model.addRow(rowData);//add with insert key
}else if(row<0 && evt.getKeyCode() == KeyEvent.VK_INSERT ){
System.err.println("No Row insert..!");
}
if (evt.getKeyCode() == KeyEvent.VK_DELETE && row < 0) {
} else if (evt.getKeyCode() == KeyEvent.VK_DELETE && row > -1) {
model.removeRow(row);//remov with delete key.
}
}catch(ArrayIndexOutOfBoundsException e){
if (evt.getKeyCode() == KeyEvent.VK_DELETE){
JOptionPane.showMessageDialog(null, "Please Choose a Row To Delete..");
}
else if(evt.getKeyCode() == KeyEvent.VK_INSERT ){
JOptionPane.showMessageDialog(null, "Please Click Inside The Table To Add new Row..");
}
}
}