|
|
|
Re: arrayindexoutofbounds when adding a new element to a tableviewer [message #517130 is a reply to message #517117] |
Fri, 26 February 2010 11:14 |
Vijay Raj Messages: 608 Registered: July 2009 |
Senior Member |
|
|
In
org.eclipse.jface.viewers.AbstractTableViewer$VirtualManager .notVisibleAdded(AbstractTableViewer.java:127)
/**
* A non visible item has been added.
*
* @param element
* @param index
*/
public void notVisibleAdded(Object element, int index) {
int requiredCount = doGetItemCount() + 1;
Object[] newCache = new Object[requiredCount];
System.arraycopy(cachedElements, 0, newCache, 0, index);
if (index < cachedElements.length) {
System.arraycopy(cachedElements, index, newCache, index + 1,
cachedElements.length - index);
}
newCache[index] = element;
cachedElements = newCache;
doSetItemCount(requiredCount);
}
array copy happens from src "cachedElements" to new array...
This cachedElements is updated only in refresh of the tableviewer...
Since Luca did table.removeAll hence the cachedElements was not updated hence the target array and source array to be copyed are of diffrent size...
Hence ArrayIndexOutOfBoundsException....
---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
|
|
|
|
Re: arrayindexoutofbounds when adding a new element to a tableviewer [message #517556 is a reply to message #517130] |
Mon, 01 March 2010 09:55 |
Luca Ferrari Messages: 159 Registered: November 2009 |
Senior Member |
|
|
vijay wrote on Fri, 26 February 2010 06:14 | In
org.eclipse.jface.viewers.AbstractTableViewer$VirtualManager .notVisibleAdded(AbstractTableViewer.java:127)
/**
* A non visible item has been added.
*
* @param element
* @param index
*/
public void notVisibleAdded(Object element, int index) {
int requiredCount = doGetItemCount() + 1;
Object[] newCache = new Object[requiredCount];
System.arraycopy(cachedElements, 0, newCache, 0, index);
if (index < cachedElements.length) {
System.arraycopy(cachedElements, index, newCache, index + 1,
cachedElements.length - index);
}
newCache[index] = element;
cachedElements = newCache;
doSetItemCount(requiredCount);
}
array copy happens from src "cachedElements" to new array...
This cachedElements is updated only in refresh of the tableviewer...
Since Luca did table.removeAll hence the cachedElements was not updated hence the target array and source array to be copyed are of diffrent size...
Hence ArrayIndexOutOfBoundsException....
|
Thanks, now it is clear why I got the array index out of bound. Thanks for the explaination, really interesting.
|
|
|
Powered by
FUDForum. Page generated in 0.03470 seconds