将数据从jtable存储到数组中

时间:2014-03-10 09:32:23

标签: java swing jtable numberformatexception

我在我的应用程序中使用jtable。我想将jtable数据存储到数组中。而我将数据输入到表中,当我按下删除按钮删除单元格中的数据时然后单击按钮将数据存储到数组中,由于按下删除按钮,显示错误NumberFormatException。如何解决此问题?我的代码是

        int source = 0;
        int temp = Integer.MAX_VALUE;
        int dist = 0;
        adjacencyMatrix = new int[nodes][nodes];
        for (int row = 0; row < dtm.getRowCount(); row++) {
            for (int col = 1; col < dtm.getColumnCount(); col++) {

                if (dtm.getValueAt(row, col) == null || (dtm.getValueAt(row, col) == "") || (dtm.getValueAt(row, col) == " ")) {
                    adjacencyMatrix[row][col - 1] = Integer.MAX_VALUE;
                } else {

                    adjacencyMatrix[row][col - 1] = Integer.parseInt((String) dtm.getValueAt(row, col));
                    // System.out.println("row ----" + row + "------" + (col - 1) + "------" + adjacencyMatrix[row][col - 1]);
                }
            }
        }
    } catch (Exception ex) {
        System.out.println(ex);
        ex.printStackTrace();
    }

}

0 个答案:

没有答案