|
NegativeArraySizeException |
Posted by Michael Opitz on Mar-15-2016 15:42 |
|
Hi Peter,
during testing of our product, we noticed the following error (we use Chartdirector 5.1.1):
Exception in thread "AWT-EventQueue-0" java.lang.NegativeArraySizeException
at ChartDirector.TrendLayer.d(SourceFile:239)
at ChartDirector.PlotArea.a(SourceFile:472)
at ChartDirector.XYChart.b(SourceFile:901)
at ChartDirector.BaseChart.a(SourceFile:1071)
at ChartDirector.BaseChart.makeChart(SourceFile:865)
at ChartDirector.BaseChart.makeChart3(SourceFile:870)
at ChartDirector.ChartViewer.b(SourceFile:716)
at ChartDirector.ChartViewer.setChart(SourceFile:706)
My colleage does not know which chart was on display and it was not possible to reproduce the issue, so I am afraid, I can not provide further details.
Could you give me a hint, what could be wrong?
regards,
Michael |
Re: NegativeArraySizeException |
Posted by Peter Kwan on Mar-16-2016 02:50 |
|
Hi Michael,
Based on the location of the error, the error can occur if the plot area width is negative.
Would you mind to check if the plot area width (usually configured with the XYChat.setPlotArea API, and can be modified with XYChart.packPlotArea) can be negative in your code?
If the plot area width is a hard coded positive number, it will not be negative. However, if it is a computed variable, please check if it can go negative.
In one case, one of our customers compute the plot area width by subtracting a certain amount from the chart width, and compute the chart width based on the window width. The code crashes when the window is minimized, as the window can become so small that the plot area width can be negative.
If the plot area width is computed, one method is to force a minimum size such as 100. For example, instead of using a variable "myWidth" as the plot area width, the code can be modified to "Math.max(100, myWidth)".
Regards
Peter Kwan |
|