shuaiwangVM / achartengine

Automatically exported from code.google.com/p/achartengine
0 stars 0 forks source link

CombinedTemperatureChart.java at r517 crashes #297

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Compile and run r517
2. Choose Combined temperature
3. Crashes

Following error log is produced

    FATAL EXCEPTION: main
    java.lang.IndexOutOfBoundsException: Invalid index 1, size is 0
        at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
        at java.util.ArrayList.add(ArrayList.java:143)
        at org.achartengine.util.IndexXYMap.put(IndexXYMap.java:42)
        at org.achartengine.model.XYSeries.add(XYSeries.java:155)
        at org.achartengine.chartdemo.demo.chart.CombinedTemperatureChart.execute(CombinedTemperatureChart.java:100)
        at org.achartengine.chartdemo.demo.ChartDemo.onListItemClick(ChartDemo.java:107)
        at android.app.ListActivity$2.onItemClick(ListActivity.java:319)

This is caused by 

[CombinedTemperatureChart.java]
    XYValueSeries sunSeries = new XYValueSeries("Sunshine hours");
    sunSeries.add(1, 35, 4.3);

It will trigger function XYSeries's add(int index, double x, double y)

If I change it to 

    XYValueSeries sunSeries = new XYValueSeries("Sunshine hours");
    sunSeries.add(1., 35, 4.3);

It works fine, as function XYValueSeries's add(double x, double y, double 
value) will be triggered.

I tested with r439. No crash happens. This is because in r439,  XYSeries's 
add(int index, double x, double y) is not added yet.

So, is sunSeries.add(1., 35, 4.3) as correct code, or should it be considered 
as temporary workaround?

Original issue reported on code.google.com by yancheng...@gmail.com on 15 Apr 2013 at 11:40

GoogleCodeExporter commented 9 years ago
Good catch!

Original comment by 4viewsoft@gmail.com on 13 May 2013 at 6:01