2011年8月6日 星期六

[java] (10) JTable : Resolve jTable1.getValueAt(i,j) get null become NullPointerException


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 :



JTable Cell Empty Validation: How to check or know JTable cell is empty or not and also avoid null or space entry validation in JTable cell before saving JTable data in Database

0 意見:

張貼留言