我需要从表JTable
中读取数据。问题是该表可能包含空单元格。在这种情况下,错误消息是:
线程中的异常“AWT-EventQueue-0”java.lang.NullPointerException
如何避免此错误消息?
mdArrivals = new QueryTableModelFS();
tbArrivals = new JTable(mdArrivals);
String STA = mdArrivals.getValueAt(i,1).toString();
答案 0 :(得分:3)
只需检查一下,阅读对象mdArrivals.getValueAt(i,1)
,然后检查是否为空调用toString
Object value = mdArrivals.getValueAt(i,1);
if (value!=null)
{
String sta = value.toString();
}
答案 1 :(得分:0)
String value= String.valueOf(jTable1.getValueAt(row, col));