JTable : Resolve jTable1.getValueAt(i,j) get null become NullPointerException
一開始都解不出來,後來我想到可以用 try .. catch這個方法來解決。
public boolean vaildCheck(){
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
try {
String om = jTable1.getValueAt(i, j).toString();
System.out.println("\n Value ="+om+ " and Length :"+om.length());
if(om.trim().length()==0){
return false;
}
}catch(NullPointerException e){
jTable1.setValueAt(0, i, j);
}
}
}
return true;
}
Reference :
0 意見:
張貼留言