簡體   English   中英

線程“ AWT-EventQueue-0”中的異常java.lang.NullPointerException

[英]Exception in thread “AWT-EventQueue-0” java.lang.NullPointerException

當我嘗試從表中添加列時,它們給了我這個錯誤。

private void SAVEALLActionPerformed(java.awt.event.ActionEvent evt)
{                                        
    model=(DefaultTableModel)tblCont.getModel();
    int col=tblCont.getColumnCount();

    String[]field=new String[col-2];
    String[]value=new String[col-2];
    field[0]="ID";
    field[col-3]="Total";
    int pop=1;
    for (int i = 3; i < col-1; i++) {
    field[pop]=String.valueOf(tblCont.getColumnName(i));
    pop++;
    }


    try {   

        for(int i=0;i<tblCont.getRowCount();i++){
            int opo=1;
          int test=0; int tes=0;
        value[0]=String.valueOf(model.getValueAt(i, 0));    
            for (int j = 3; j < col-1; j++) {

                value[opo]=String.valueOf(model.getValueAt(i, j));
                //Here points my error
                tes =tes + Integer.parseInt(value[pop].trim());
              test=test+tes;
                opo++;
            }

           String tet = Integer.toString(test);
           value[col-4]=tet;
           JOptionPane.showMessageDialog(this, tet);
            UpdateRec(field, value, "contribution");
        }


    } catch (SQLException e) {
        JOptionPane.showMessageDialog(this, e.getMessage());

    }

    TableClearCont();
    ShowContFile();
}                                      

表中的值為空。

做一些基本的調試。 就像是;

String cellValue = model.getValueAt(i, j).toString().trim();
//Here points my error
System.out.println(cellValue + " : " + i + " : " + j);
tes += Integer.parseInt(cellValue);
value[opo] = cellValue;

一旦知道哪個值為空,就可以修復表中的數據。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM