簡體   English   中英

Glazedlist表的第一行中的IndexOutOfBoundsException?

[英]IndexOutOfBoundsException in the first row of Glazedlist table?

我已經構建了3個Glazedlist表。 當用戶點擊第一個表的行時,它會在第二個表中顯示列表。 當單擊第二個表中的行時,它將替換第3個表中的其他列表。 問題是,當我單擊第一個表中的第一行時,有時會出現異常。

有沒有人知道為什么我會得到IndexOutOfBoundsException以及如何擺脫它?

Exception in thread "AWT-EventQueue-1" java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    at java.util.ArrayList.RangeCheck(ArrayList.java:546)
    at java.util.ArrayList.get(ArrayList.java:321)
    at ca.odell.glazedlists.impl.gui.ThreadProxyEventList.applyChangeToCache(ThreadProxyEventList.java:175)
    at ca.odell.glazedlists.impl.gui.ThreadProxyEventList.access$600(ThreadProxyEventList.java:68)
    at ca.odell.glazedlists.impl.gui.ThreadProxyEventList$UpdateRunner.listChanged(ThreadProxyEventList.java:237)
    at ca.odell.glazedlists.event.ListEventAssembler$ListEventFormat.fire(ListEventAssembler.java:412)
    at ca.odell.glazedlists.event.ListEventAssembler$ListEventFormat.fire(ListEventAssembler.java:409)
    at ca.odell.glazedlists.event.SequenceDependenciesEventPublisher$SubjectAndListener.firePendingEvent(SequenceDependenciesEventPublisher.java:445)
    at ca.odell.glazedlists.event.SequenceDependenciesEventPublisher.fireEvent(SequenceDependenciesEventPublisher.java:344)
    at ca.odell.glazedlists.event.ListEventAssembler.commitEvent(ListEventAssembler.java:316)
    at ca.odell.glazedlists.impl.gui.ThreadProxyEventList$UpdateRunner.run(ThreadProxyEventList.java:225)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
    at di.pri.debutil.gui.debEventQueue.dispatchEvent(debEventQueue.java:63)
    at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

碼:

// build the table
EventList<Treat> TreatEventList = summaryModel.getTreatEvenList();
String[] propertyNames = new String[]{"PlanId", "Number", "Type","dication","stimulation","dication2","Date","Outcome","rank","version"};
String[] columnLabels = new String[]{"pnr", "NBNR", "handeling","Supp","Stim1","Stim2","date","Outcome","Rank","Version"};
TableFormat<Treat> tableFormat = GlazedLists.tableFormat(Treat.class, propertyNames, columnLabels);
SortedList<Treat> TreatSortedList = new SortedList<Treat>(TreatEventList, null);
cabinaTable = new WebTable(new EventTableModel<Treat>(TreatSortedList, tableFormat)); 

// Configure the Table
TableComparatorChooser tableSorter = TableComparatorChooser.install(cabinaTable, TreatSortedList, TableComparatorChooser.SINGLE_COLUMN);
tableSorter.appendComparator(1, 0, true);
cabinaTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
cabinaTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
cabinaTable.addMouseListener(new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {
        int row = cabinaTable.rowAtPoint(e.getPoint());
        DHDPnr = cabinaTable.getValueAt(row, 0).toString();
        //at this point i set the evntlist for second Glazedlist table
        summaryModel.retrieveAllPredomainWithDHDPnr(dosNr(), DHDPnr);
    }
});

當用戶點擊第一個表的行時,它會在第二個表中顯示列表。 當單擊第二個表中的行時,它將替換第3個表中的其他列表

這給了我一個提示,你可以使用基於1的索引而不是基於0的索引,當嘗試訪問索引為0的空ArrayList時也會導致IndexOutOfBoundsException

很難用顯示的代碼告訴你,但是當你點擊第一行並且它試圖獲取數據時,代碼中的某個地方就沒有數據了。 因此,當您填充應該存在的數據時,由於某種原因,它不會這樣做。 通過查看所有代碼會更容易分辨,因為我之前沒有使用過GlazedLists。

大小:0表示它錯過了填充數據或某些內容為空。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM