java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1

Appcelerator JIRA | Rodolfo Perottoni | 1 year ago
  1. 0

    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: {code:javascript} _.each($.scrollableView.getViews(), function(view) { $.scrollableView.removeView(view); }); {code} * 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: {code:java} [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) {code} How i've solved it: Before removing the ScrollableView views, i've used this method: {code:javascript} $.scrollableView.scrollToView($.scrollableView.getViews()[0]); {code}

    Appcelerator JIRA | 1 year ago | Rodolfo Perottoni
    java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1
  2. 0

    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: {code:javascript} _.each($.scrollableView.getViews(), function(view) { $.scrollableView.removeView(view); }); {code} * 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: {code:java} [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) {code} How i've solved it: Before removing the ScrollableView views, i've used this method: {code:javascript} $.scrollableView.scrollToView($.scrollableView.getViews()[0]); {code}

    Appcelerator JIRA | 1 year ago | Rodolfo Perottoni
    java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1
  3. Speed up your debug routine!

    Automated exception search integrated into your IDE

  4. 0

    IndexOutOfBoundsException when clicking Button as Target View

    GitHub | 2 years ago | androidfu
    java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1
  5. 0

    Android - Invalid index 1, size is 1 - out of bounds

    Stack Overflow | 3 years ago | James King
    java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1
Not finding the right solution?
Take a tour to get the most out of Samebug.

Tired of useless tips?

Automated exception search integrated into your IDE

Root Cause Analysis

  1. java.lang.IndexOutOfBoundsException

    Invalid index 1, size is 1

    at java.util.ArrayList.throwIndexOutOfBoundsException()
  2. Java RT
    ArrayList.get
    1. java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
    2. java.util.ArrayList.get(ArrayList.java:308)
    2 frames
  3. ti.modules.titanium
    TiUIScrollableView$2.onPageSelected
    1. ti.modules.titanium.ui.widget.TiUIScrollableView$2.onPageSelected(TiUIScrollableView.java:159)
    1 frame
  4. Android Support v4
    ViewPager$PagerObserver.onChanged
    1. android.support.v4.view.ViewPager.scrollToItem(ViewPager.java:578)
    2. android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:555)
    3. android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:513)
    4. android.support.v4.view.ViewPager.dataSetChanged(ViewPager.java:912)
    5. android.support.v4.view.ViewPager$PagerObserver.onChanged(ViewPager.java:2826)
    5 frames
  5. Android Platform
    DataSetObservable.notifyChanged
    1. android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
    1 frame
  6. Android Support v4
    PagerAdapter.notifyDataSetChanged
    1. android.support.v4.view.PagerAdapter.notifyDataSetChanged(PagerAdapter.java:276)
    1 frame
  7. ti.modules.titanium
    ScrollableViewProxy.handleMessage
    1. ti.modules.titanium.ui.widget.TiUIScrollableView.removeView(TiUIScrollableView.java:350)
    2. ti.modules.titanium.ui.ScrollableViewProxy.handleMessage(ScrollableViewProxy.java:131)
    2 frames
  8. Android Platform
    ActivityThread.main
    1. android.os.Handler.dispatchMessage(Handler.java:98)
    2. android.os.Looper.loop(Looper.java:135)
    3. android.app.ActivityThread.main(ActivityThread.java:5254)
    3 frames
  9. Java RT
    Method.invoke
    1. java.lang.reflect.Method.invoke(Native Method)
    2. java.lang.reflect.Method.invoke(Method.java:372)
    2 frames
  10. Android
    ZygoteInit.main
    1. com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
    2. com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
    2 frames