0

i have received a mail from Google play regarding a crash in my app. the stack trash as follow

java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
at java.util.ArrayList.get(ArrayList.java:304)
at com.mycompanyname.myappname.Main$2.onScrollingFinished(Main.java:161)
at android.wheel.widget.WheelView.notifyScrollingListenersAboutEnd(WheelView.java:295)
at android.wheel.widget.WheelView$1.onFinished(WheelView.java:156)
at android.wheel.widget.WheelScroller.finishScrolling(WheelScroller.java:248)
at android.wheel.widget.WheelScroller$2.handleMessage(WheelScroller.java:220)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4898)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
at dalvik.system.NativeStart.main(Native Method)

how i found and fix this because i have tested it thoroughly but not found this type of error. any suggestion how to find that error.

here is my code for wheel scrolling

public void onScrollingFinished(WheelView wheel) {
            WheelScrolled = false;

            System.gc();

            ivImage.setImageResource(images[wheelview.getCurrentItem()]);
            tvName.setText(names[wheelview.getCurrentItem()]);              

            tvText.setText(_dataList.get(wheelview.getCurrentItem()).data);     

            System.gc();

        }
    });
  • 1
    Post your code. Your array has no elements in onScrollingFinished – Tarun Aug 06 '13 at 06:06
  • @Tarun i have posted my code where i am using arraylist to set data –  Aug 06 '13 at 06:25
  • Put a try catch statement or check if `cwheelview.getCurrentItem()` is NULL or not – Tarun Aug 06 '13 at 06:34
  • @Tarun after searching, i think the problem is in my arraylist(memory problem) i have a button to open another activity without finishing first activity. after 10-15 min when i switched back to previous activity the arraylist lost it's values. the app is running perfectly in new phones. but this problem is only in old phones because my app targeting android 1.6 and up. now i am changing it to 2.2 and up. may this solve my problem. i have just testes my app in a old htc phone targeting android 1.6. –  Aug 06 '13 at 06:45
  • How are you initializing your array? Where are you initializing it? You should avoid calling gc() more on it http://stackoverflow.com/a/3118939/786337 – Tarun Aug 06 '13 at 06:53
  • @Tarun yes you are right i need to comment System.gc() because of no need here. i am initializing array in my activity's onCreate() by calling a web service. thanks for your help. if you can post all of your comments as answer i will accept.. –  Aug 06 '13 at 07:09
  • Posted as answer.. thanks – Tarun Aug 06 '13 at 07:12

1 Answers1

0

Your array has no elements in onScrollingFinished

Put a try catch statement or check if wheelview.getCurrentItem() is NULL or not

How are you initializing your array? Where are you initializing it? You should avoid calling gc() more on it

Community
  • 1
  • 1
Tarun
  • 13,727
  • 8
  • 42
  • 57