2

我需要从表中读取数据JTable。问题是该表可能包含空单元格。在这种情况下,错误消息是:

线程“AWT-EventQueue-0”中的异常 java.lang.NullPointerException

如何避免此错误消息?

mdArrivals = new QueryTableModelFS();

tbArrivals = new JTable(mdArrivals);

String STA = mdArrivals.getValueAt(i,1).toString();
4

2 回答 2

3

只需检查它,读取对象 mdArrivals.getValueAt(i,1),然后检查是否为空调用toString

Object value = mdArrivals.getValueAt(i,1);
if (value!=null)
{
    String sta = value.toString();
}
于 2013-06-14T11:42:46.983 回答
0
        String value= String.valueOf(jTable1.getValueAt(row, col));
于 2018-02-19T10:21:23.007 回答