Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要从表中读取数据JTable。问题是该表可能包含空单元格。在这种情况下,错误消息是:
JTable
线程“AWT-EventQueue-0”中的异常 java.lang.NullPointerException
如何避免此错误消息?
mdArrivals = new QueryTableModelFS(); tbArrivals = new JTable(mdArrivals); String STA = mdArrivals.getValueAt(i,1).toString();
只需检查它,读取对象 mdArrivals.getValueAt(i,1),然后检查是否为空调用toString
mdArrivals.getValueAt(i,1)
toString
Object value = mdArrivals.getValueAt(i,1); if (value!=null) { String sta = value.toString(); }
String value= String.valueOf(jTable1.getValueAt(row, col));