ArrayIndexOutOfBoundsException when clearing/adding data
ArrayIndexOutOfBoundsException when clearing/adding data
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
Yes, I downloaded it some days ago and I'd used it before I opened the thread. I send you the example as a small jar File. It was built with Eclipse 3.2 and crashes reliable on our machine:Marc wrote:Could you confirm please that you're using the latest build version, Build 1.0.1.825.
Win XP Pro. We tried JRE 1.4 / 1.5 / 1.6. No difference.
Best Regards
Thomas
Thomas
-
- Site Admin
- Posts: 14730
- Joined: Mon Jun 09, 2003 4:00 am
- Location: Banyoles, Catalonia
- Contact:
Hi Thomas,
I haven't found the project you mention. Where did you send it?
Thanks in advance!
I haven't found the project you mention. Where did you send it?
Thanks in advance!
Best Regards,
Narcís Calvet / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Sent it to info@steema.comnarcis wrote:I haven't found the project you mention. Where did you send it?
Best Regards
Thomas
Thomas
Hello,
The program you sent runs but doesn't close (looking at your code in the previous post that's by design, not a problem). Your example runs ok when tested on Win2003 and on WinXP. The XP machine was previously unprepared and the JRE 5 (1.5) runtime environment was installed.
Have you tried your application on different machines?
Regards,
Marc
The program you sent runs but doesn't close (looking at your code in the previous post that's by design, not a problem). Your example runs ok when tested on Win2003 and on WinXP. The XP machine was previously unprepared and the JRE 5 (1.5) runtime environment was installed.
Have you tried your application on different machines?
Regards,
Marc
Now I've tried it. The problem occurs on a dual core machine. It doesn't occur on a second single core machine. Have you tested it on a dual core PC?Marc wrote:Have you tried your application on different machines?
I run the test program from a shell. If no messages are thrown all is fine. If there are problems, messages appear in the shell.
And yes, it was the first AWT app we'd written. Perhaps the Window Close message isn't processed in a right way, therefore the window can't be closed properly.
Best Regards
Thomas
Thomas
Hello,
Yes, the Win2003 test machine is Core 2 Duo. The XP machine is Dual Core (Pentium D).
Do you have any more information on the error messages thrown? An option to get a clearer location on the error might be to unwrap the TeeChart Jar to source and debug it as part of the project source.
Re. AWT App close.
Yes, we added the following to the example code to close our own test copy of your project:
Regards,
Marc
Yes, the Win2003 test machine is Core 2 Duo. The XP machine is Dual Core (Pentium D).
Do you have any more information on the error messages thrown? An option to get a clearer location on the error might be to unwrap the TeeChart Jar to source and debug it as part of the project source.
Re. AWT App close.
Yes, we added the following to the example code to close our own test copy of your project:
Code: Select all
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) { dispose();}
});
Marc
Hello Marc,Marc wrote:Hello,
Do you have any more information on the error messages thrown? An option to get a clearer location on the error might be to unwrap the TeeChart Jar to source and debug it as part of the project source.
Regards,
Marc
here is the error message:
>>>>>>>>>>>>>>>> Begin Message<<<<<<<<<<<<<<<<<<
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 214
at com.steema.teechart.styles.FastLine.calcPosition(FastLine.java:208)
at com.steema.teechart.styles.FastLine.drawValue(FastLine.java:246)
at com.steema.teechart.styles.FastLine.draw(FastLine.java:228)
at com.steema.teechart.styles.Series.drawSeries(Series.java:2222)
at com.steema.teechart.Chart.internalDraw(Chart.java:670)
at com.steema.teechart.Chart.paint(Chart.java:1807)
at com.steema.teechart.TChart.paintComponent(TChart.java:568)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintWithOffscreenBuffer(Unknown Source)
at javax.swing.JComponent.paintDoubleBuffered(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 1164
at com.steema.teechart.styles.ValueList.calcStats(ValueList.java:314)
at com.steema.teechart.styles.ValueList.getMaximum(ValueList.java:357)
at com.steema.teechart.styles.Series.getMaxYValue(Series.java:3719)
at com.steema.teechart.Chart.internalMinMax(Chart.java:1584)
at com.steema.teechart.axis.Axis.calcMinMax(Axis.java:1122)
at com.steema.teechart.axis.Axis.adjustMaxMin(Axis.java:355)
at com.steema.teechart.axis.Axes.adjustMaxMin(Axes.java:235)
at com.steema.teechart.Chart.calcAxisRect(Chart.java:1927)
at com.steema.teechart.Chart.internalDraw(Chart.java:630)
at com.steema.teechart.Chart.paint(Chart.java:1807)
at com.steema.teechart.TChart.paintComponent(TChart.java:568)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintWithOffscreenBuffer(Unknown Source)
at javax.swing.JComponent.paintDoubleBuffered(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
>>>>>>>>>>>>> End Message <<<<<<<<<<<<<<<<<<<<<<
Due to the loop, the error message appears several times (with a different index number each time).
Best Regards
Thomas
Thomas