简体   繁体   English

Glazedlist表的第一行中的IndexOutOfBoundsException?

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

I have build 3 Glazedlist table. 我已经构建了3个Glazedlist表。 when the user clicked on the row of the first table it shows list in the second table. 当用户点击第一个表的行时,它会在第二个表中显示列表。 when click on row in second table it displaies other list in the 3th table. 当单击第二个表中的行时,它将替换第3个表中的其他列表。 Problem is when i click the first row in first table sometimes following exception appears. 问题是,当我单击第一个表中的第一行时,有时会出现异常。

Does any body know Why do i get IndexOutOfBoundsException and how get rid of it? 有没有人知道为什么我会得到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)

Code: 码:

// 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);
    }
});

when the user clicked on the row of the first table it shows list in the second table. 当用户点击第一个表的行时,它会在第二个表中显示列表。 when click on row in second table it displaies other list in the 3th table 当单击第二个表中的行时,它将替换第3个表中的其他列表

This gives me a hint that you could be using 1-based indexing instead of 0-based indexing, also leading to IndexOutOfBoundsException when trying to access an empty ArrayList with index 0. 这给了我一个提示,你可以使用基于1的索引而不是基于0的索引,当尝试访问索引为0的空ArrayList时也会导致IndexOutOfBoundsException

It is hard to tell with the code shown, but somewhere in the code when you click on the first row and it is trying to get the data, there is no data. 很难用显示的代码告诉你,但是当你点击第一行并且它试图获取数据时,代码中的某个地方就没有数据了。 So when you fill the data that should be there it isn't doing that for some reason. 因此,当您填充应该存在的数据时,由于某种原因,它不会这样做。 It would be easier to tell by looking at all the code as I haven't used GlazedLists before. 通过查看所有代码会更容易分辨,因为我之前没有使用过GlazedLists。

Size: 0 means it missed filling the data or something was null. 大小:0表示它错过了填充数据或某些内容为空。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM