Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-20116

Android - ScrollableView removeView(): java.lang.IndexOutOfBoundsException: Invalid index X, size is X

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Medium
    • Resolution: Fixed
    • Affects Version/s: Release 5.0.2, Release 5.1.1
    • Fix Version/s: Release 5.4.0
    • Component/s: Android
    • Environment:

      Mac OS X 10.10.5
      Ti SDK 5.0.3.v20151002003129
      Studio 4.3.0.201509151348

    • Story Points:
      5
    • Sprint:
      2016 Sprint 07 SDK

      Description

      This is happening only in the android platform. Seems like when you call the ScrollableView.removeView() method it automatically jumps to the previous view if you're currently viewing the one you're trying to delete. However, that fires an exception.
      How to reproduce:

      • Create an Android-enabled project with a single, main view.
      • Add to that view a ScrollableView and a Button below it.
      • Add 3 empty views to the ScrollableView.
      • Add an event to the button which fires the following code:

        _.each($.scrollableView.getViews(), function(view) {
             $.scrollableView.removeView(view);
        });
        

      • Click the button with the view number 1 focused: it will work.
      • Reopen the app (so the views get added again), browse to the 3rd view and click the button.
        It will throw this exception:

      [ERROR] :  TiApplication: (main) [47704,48391] Sending event: exception on thread: main msg:java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1; Titanium 5.0.3,2015/10/02 00:31,d4496fe
      [ERROR] :  TiApplication: java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1
      [ERROR] :  TiApplication: 	at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
      [ERROR] :  TiApplication: 	at java.util.ArrayList.get(ArrayList.java:308)
      [ERROR] :  TiApplication: 	at ti.modules.titanium.ui.widget.TiUIScrollableView$2.onPageSelected(TiUIScrollableView.java:159)
      [ERROR] :  TiApplication: 	at android.support.v4.view.ViewPager.scrollToItem(ViewPager.java:578)
      [ERROR] :  TiApplication: 	at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:555)
      [ERROR] :  TiApplication: 	at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:513)
      [ERROR] :  TiApplication: 	at android.support.v4.view.ViewPager.dataSetChanged(ViewPager.java:912)
      [ERROR] :  TiApplication: 	at android.support.v4.view.ViewPager$PagerObserver.onChanged(ViewPager.java:2826)
      [ERROR] :  TiApplication: 	at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
      [ERROR] :  TiApplication: 	at android.support.v4.view.PagerAdapter.notifyDataSetChanged(PagerAdapter.java:276)
      [ERROR] :  TiApplication: 	at ti.modules.titanium.ui.widget.TiUIScrollableView.removeView(TiUIScrollableView.java:350)
      [ERROR] :  TiApplication: 	at ti.modules.titanium.ui.ScrollableViewProxy.handleMessage(ScrollableViewProxy.java:131)
      [ERROR] :  TiApplication: 	at android.os.Handler.dispatchMessage(Handler.java:98)
      [ERROR] :  TiApplication: 	at android.os.Looper.loop(Looper.java:135)
      [ERROR] :  TiApplication: 	at android.app.ActivityThread.main(ActivityThread.java:5254)
      [ERROR] :  TiApplication: 	at java.lang.reflect.Method.invoke(Native Method)
      [ERROR] :  TiApplication: 	at java.lang.reflect.Method.invoke(Method.java:372)
      [ERROR] :  TiApplication: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
      [ERROR] :  TiApplication: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
      

      How i've solved it:
      Before removing the ScrollableView views, i've used this method:

      $.scrollableView.scrollToView($.scrollableView.getViews()[0]);
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                msamah Ashraf Abu (Inactive)
                Reporter:
                rdperottoni Rodolfo Perottoni
                Reviewer:
                Ashraf Abu (Inactive)
              • Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Titanium SDK/CLI <> Titanium Mobile
                    Synced with:
                    TIMOB-20768
                    Sync status:
                    ERROR
                    Last received:
                    Last sent:

                    Git Integration