私はで作成しましたJTable
、DefaultTableModel
私は内部とすべてにデータを追加します、しかし私がそれを取得しようとすると私はNullPointerException
ここに行きます:
DefaultTableModel dm = (DefaultTableModel)finishedSaleTable.getModel();
private DefaultTableModel finishedSaleModel;
private JTable finishedSaleTable;
public SaleUI() {
String finishedSaleColumns [] = {"#", "Customer", "Employee", "Products", "# Products", "Discount", "Price", "Date"};
finishedSaleModel = new DefaultTableModel(null, finishedSaleColumns);
finishedSaleTable = new JTable(finishedSaleModel){
public boolean isCellEditable(int rowIndex, int colIndex) {
return false;
}
};
finishedSaleTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
finishedSaleTable.getColumnModel().getColumn(0).setPreferredWidth(40);
finishedSaleTable.getColumnModel().getColumn(1).setPreferredWidth(100);
finishedSaleTable.getColumnModel().getColumn(2).setPreferredWidth(100);
finishedSaleTable.getColumnModel().getColumn(3).setPreferredWidth(85);
finishedSaleTable.getColumnModel().getColumn(4).setPreferredWidth(90);
finishedSaleTable.getColumnModel().getColumn(6).setPreferredWidth(75);
finishedSaleTable.getColumnModel().getColumn(7).setPreferredWidth(125);
JScrollPane finishedSaleTableScroll = new JScrollPane(finishedSaleTable);
}
private void finishedSaleClearList()
{
DefaultTableModel dm = (DefaultTableModel)finishedSaleTable.getModel();
while(dm.getRowCount() > 0)
dm.removeRow(0);
}
完全なエラー:
Exception in thread "main" java.lang.NullPointerException
at ui.SalesUI.finishedSaleClearList(SalesUI.java:641) // DefaultTableModel line
at ui.SalesUI.finishedSaleUpdateList(SalesUI.java:674) // where I call the method
at ui.SalesUI.<init>(SalesUI.java:248)
at ui.SalesUI.main(SalesUI.java:752)