SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components


I am working on the CreateMultiPaneStockChartFragment example. I modified the example, like showing legend checkboxes and some other stuff. I am getting the following exception, but just sometimes (like 30% of time). It happens as soon as I open the fragment.

2019-02-19 12:32:59.551 12534-12534/com.yyyyy.xxxE/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.yyyyy.xxxE, PID: 12534
    java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
        at java.util.ArrayList.get(
        at com.scichart.charting.visuals.legend.SciChartLegend$d.a(SourceFile:278)
        at com.scichart.charting.visuals.legend.SciChartLegend$
        at android.os.Handler.handleCallback(
        at android.os.Handler.dispatchMessage(
        at android.os.Looper.loop(
        at java.lang.reflect.Method.invoke(Native Method)

Obviously there is some problem with get() on an empty ArrayList, but I am having a hard time to debug where exactly this happens.

I have reviewed my source code multiple times and can not find the cause. What could be the problem?

I am using v2.2.1.2391.

  • Yura Khariton
    It looks like it could be some race condition or maybe result of some exception. Do you see any other errors in logcat except IndexOutOfBoundsException which you reported? Can you reproduce this exception in example without your modifications? Can you provide a modified version of CreateMultiPaneStockChartFragment class?
  • Primoz
    Hi Yura, sorry for delay. It took me some time to pinpoint the issue. I found out that this crash happens if you add LegendModifier to surface BEFORE any model has been added. It is reproducable with the example; just move all addModel() after addinf modifiers and it will crash. You can also check my simplified code here:
  • Primoz
    I would like to add that I have modified the example such that I first initialize “fixed, non changeable” chart elements, such as x axis, y axes (I have different Y axes for price, macd, rsi, vol), modifiers. I do this in onViewCreated(). Then I have a runnable that runs every 10 sec which retrieves latest price data, and replaces the series and refresh annotations (I always clear renderableseries and annotation before this call and then add new).
  • Primoz
    I think the problem here was that I set LegendModifier before adding any model (series). This was with older version and I have now rewritten my code and it works, so I will not bother with this anymore.
  • You must to post comments
Showing 0 results