我正在嘗試用兩個 Jtables 創(chuàng)建一個 gui。一個輸出對象 Bike(如果可用),一個輸出對象 Rent。但是默認表模型不斷返回空點異常。如何使用值數(shù)組列表填充 JTable,然后將其添加到 JPanel 網(wǎng)格布局。我曾嘗試使用默認表模型和 TableModel 以及搜索無用的解決方案。這是一個基本的 GUI 學(xué)校項目存放數(shù)組的主類public static final ArrayList<Bike> bikes = new ArrayList<>(); public static final ArrayList<Customer> customers = new ArrayList<>(); public static final ArrayList<Rent> rents = new ArrayList<>(); ArrayList<Rent> toRemove = new ArrayList<Rent>(); //Create variables private int customerID = 0; private final LocalDate currentDate = LocalDate.now(); //Main Method public static void main(String args[]) { //Create gui GUI fr = new GUI(); fr.setSize(1000, 600); fr.setVisible(true); fr.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); //Create Initial Objects and fill Arrays bikes.add(new Bike("Tarmac Disk Expert", 6000.00, "Mountain", true)); bikes.add(new Bike("Epic Hardtail Comp", 3500.00, "Mountain", true)); bikes.add(new Bike("Chisel Comp", 2000.00, "Road", true)); bikes.add(new Bike("Roubaix Sport", 3500.00, "Road", false)); bikes.add(new Bike("Turbo Levi Comp", 9500.00, "City", false)); bikes.add(new Bike("Venge Pro", 9400.00, "City", true)); bikes.add(new EBike("Turbo Como 2.0 650B", 4500.00, "Ebike", true, "Full Power")); bikes.add(new EBike("Turbo Kenevo Expert", 9500.00, "Ebike", true, "Full Power")); bikes.add(new EBike("Turbo Levo FSR", 5600.00, "Ebike", true, "Full Power")); bikes.add(new EBike("Turbo Vado 4.0", 5600.00, "Ebike", true, "Power Assisted")); bikes.add(new EBike("S-Works Turbo Levo", 4000.00, "Ebike", true, "Power Assisted")); bikes.add(new EBike("Turbo Como 2.0 Low Entry", 6600.00, "Ebike", true, "Power Assisted")); customers.add(new Customer(0001, "John Smith", true, "Roubaix Sport")); customers.add(new Customer(0002, "Madamn Tuscoue", false, "N/A"));
2 回答

眼眸繁星
TA貢獻1873條經(jīng)驗 獲得超9個贊
看起來 bikesAvaliable 在 GUI 類中沒有分配給它的對象。解決此問題的一種方法是在 gui 類中創(chuàng)建 bikesAvalible 對象,或者將您在其他類中創(chuàng)建的 bikesAvaible 對象傳遞給 gui 類,以便可以使用它。

叮當(dāng)貓咪
TA貢獻1776條經(jīng)驗 獲得超12個贊
看起來bikesAvailable
變量沒有正確初始化。只需實例化它JTable bikesAvailable = new JTable();
或使用另一個構(gòu)造函數(shù):https ://docs.oracle.com/javase/7/docs/api/javax/swing/JTable.html
添加回答
舉報
0/150
提交
取消