开发者

Android getIndexOutOfBoundsException while surfing ArrayList<String>

I'm trying to surf an ArrayList of 24 positions. I'm doing that using 2 indexes in a cicle for. The r is incremented (r+=4)every time i call the onClickListener() method by clicking a button. So i put this condition out of the onClick() method:

         Here i close the onclick() and set r+=4;
         if (r<arraylist.size())
         {
             nextQuest.setOnClickListener(btn1Listener);
         }

So i ran my app and click to see if i get a crash and unfortunately i get a crash. P.s. this index is used for getting 4 answers for a related question. The questions are in another arraylist of size 6. Does anyone knows why it doesn't work.

This is my logcat error:

                07-26 12:16:32.836: ERROR/AndroidRuntime(480): FATAL EXCEPTION: main
    07-26 12:16:32.836: ERROR/AndroidRuntime(480): java.lang.IndexOutOfBoundsException
    07-26 12:16:32.836: ERROR/AndroidRuntime(480):     at java.util.AbstractList.subList(AbstractList.java:745)
    07-26 12:16:32.836: ERROR/AndroidRuntime(480):     at com.android.quizzle.MainMenuActivity$1.onClick(MainMenuActivity.java:139)
    07-26 12:16:32.836: ERROR/AndroidRuntime(480):     at android.view.View.performClick(View.java:2408)
    07-26 12:16:32.836: ERROR/AndroidRuntime(480):     at android.view.View$PerformClick.run(View.java:8816)
    07-26 12:16:32.836: ERROR/AndroidRuntime(480):     at android.os.Handler.handleCallback(Handler.java:587)
    07-26 12:16:32.836: ERROR/AndroidRuntime(480):     at android.os.Handler.dispatchMessage(Handler.java:92)
    07-26 12:16:32.836: ERROR/AndroidRuntime(480):     at android.os.Looper.loop(Looper.java:123)
    07-26 12:16:32.836: ERROR/AndroidRuntime(480):     at android.app.ActivityThread.main(ActivityThread.java:4627)
    07-26 12:16:32.836: ERROR/AndroidRuntime(480):     at java.lang.reflect.Method.invokeNative(Native Method)
    07-26 12:16:32.836: ERROR/AndroidRuntime(480):     at java.lang.reflect.Method.invoke(Method.java:521)
    07-26 12:16:32.836: ERROR/AndroidRuntime(480):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
    07-26 12:16:32.836: ERROR/AndroidRuntime(480):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
    07-26 12:16:32.836: ERROR/AndroidRuntime(开发者_开发技巧480):     at dalvik.system.NativeStart.main(Native Method)

Thanks for your support.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜