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


    • 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

    • Story Points:
    • Sprint:
      2016 Sprint 07 SDK


      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) {

      • 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:



          Issue Links



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


                • Created:

                  Backbone Issue Sync

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

                    Git Integration