ArrayIndexOutOfBoundsException when clearing/adding data
Posted: Fri Nov 09, 2007 10:22 am
Hello,
here is a simple program which - unfortunately - crashes TChart.
The problem occurred, when we wanted to show data, which is continually changing. As new data became available, we updated the TChart by:
series.clear(); // erase old data
series.add(...); // draw new data
Sometimes, this led to an ArrayIndexOutOfBoundsException.
I have condensed the problem to the example program below. The delay
(in doTest()) is inessential. It just assures a more certain crash. Without it, the crash occurs less frequently.
Also, using refreshControl(), does not improve things. Instead of an ArrayIndexOutOfBoundsException, a NullPointerException is thrown in this case.
>>>>>>>>>>>>>>>>>>> Begin Program <<<<<<<<<<<<<<<<
import java.awt.Frame;
import com.steema.teechart.TChart;
import java.awt.BorderLayout;
import com.steema.teechart.styles.FastLine;
public class AWTTest extends Frame {
private static final long serialVersionUID = 1L;
private TChart tChart = null;
private FastLine series;
private short data[];
public static void main(String[] args) {
new AWTTest();
}
public AWTTest() {
super();
initialize();
setVisible(true);
doTest();
}
private void initialize() {
this.setSize(600, 400);
this.setTitle("Frame");
tChart = new TChart();
this.add(tChart, BorderLayout.CENTER);
series = new FastLine(tChart.getChart());
data = new short[4000];
for (int i = 0; i < data.length; ++i) {
data = (short)(16000.0*Math.sin(i*0.232));
}
}
private void addSeries() {
for (int i = 0; i < data.length; ++i) {
series.add(data);
}
}
private void delay(int millis) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {}
}
private void doTest() {
for (int i = 0; i < 10; ++i) {
series.clear();
// tChart.refreshControl();
delay(100);
addSeries();
// tChart.refreshControl();
delay(100);
}
}
}
>>>>>>>>>>>>>>>>>>> End Program <<<<<<<<<<<<<<<<<
_________________
Best Regards
Thomas
here is a simple program which - unfortunately - crashes TChart.
The problem occurred, when we wanted to show data, which is continually changing. As new data became available, we updated the TChart by:
series.clear(); // erase old data
series.add(...); // draw new data
Sometimes, this led to an ArrayIndexOutOfBoundsException.
I have condensed the problem to the example program below. The delay
(in doTest()) is inessential. It just assures a more certain crash. Without it, the crash occurs less frequently.
Also, using refreshControl(), does not improve things. Instead of an ArrayIndexOutOfBoundsException, a NullPointerException is thrown in this case.
>>>>>>>>>>>>>>>>>>> Begin Program <<<<<<<<<<<<<<<<
import java.awt.Frame;
import com.steema.teechart.TChart;
import java.awt.BorderLayout;
import com.steema.teechart.styles.FastLine;
public class AWTTest extends Frame {
private static final long serialVersionUID = 1L;
private TChart tChart = null;
private FastLine series;
private short data[];
public static void main(String[] args) {
new AWTTest();
}
public AWTTest() {
super();
initialize();
setVisible(true);
doTest();
}
private void initialize() {
this.setSize(600, 400);
this.setTitle("Frame");
tChart = new TChart();
this.add(tChart, BorderLayout.CENTER);
series = new FastLine(tChart.getChart());
data = new short[4000];
for (int i = 0; i < data.length; ++i) {
data = (short)(16000.0*Math.sin(i*0.232));
}
}
private void addSeries() {
for (int i = 0; i < data.length; ++i) {
series.add(data);
}
}
private void delay(int millis) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {}
}
private void doTest() {
for (int i = 0; i < 10; ++i) {
series.clear();
// tChart.refreshControl();
delay(100);
addSeries();
// tChart.refreshControl();
delay(100);
}
}
}
>>>>>>>>>>>>>>>>>>> End Program <<<<<<<<<<<<<<<<<
_________________
Best Regards
Thomas