当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Crash OnPageChangeListener on smallFragments

问题描述:

I've a problem with the following command in my android app:

((android.support.v4.view.ViewPager.OnPageChangeListener)mSmallFragments.get(j)).onPageSelected(j);

I get:

10-17 18:43:24.691: E/AndroidRuntime(5171): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.yabeat.skmp3/com.yabeat.skipmp3.ui.YBTShopHomeActivity}: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0

10-17 18:43:24.691: E/AndroidRuntime(5171): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)

10-17 18:43:24.691: E/AndroidRuntime(5171): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)

10-17 18:43:24.691: E/AndroidRuntime(5171): at android.app.ActivityThread.access$600(ActivityThread.java:130)

10-17 18:43:24.691: E/AndroidRuntime(5171): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)

10-17 18:43:24.691: E/AndroidRuntime(5171): at android.os.Handler.dispatchMessage(Handler.java:99)

10-17 18:43:24.691: E/AndroidRuntime(5171): at android.os.Looper.loop(Looper.java:137)

10-17 18:43:24.691: E/AndroidRuntime(5171): at android.app.ActivityThread.main(ActivityThread.java:4745)

10-17 18:43:24.691: E/AndroidRuntime(5171): at java.lang.reflect.Method.invokeNative(Native Method)

10-17 18:43:24.691: E/AndroidRuntime(5171): at java.lang.reflect.Method.invoke(Method.java:511)

10-17 18:43:24.691: E/AndroidRuntime(5171): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)

10-17 18:43:24.691: E/AndroidRuntime(5171): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)

10-17 18:43:24.691: E/AndroidRuntime(5171): at dalvik.system.NativeStart.main(Native Method)

10-17 18:43:24.691: E/AndroidRuntime(5171): Caused by: java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0

10-17 18:43:24.691: E/AndroidRuntime(5171): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)

10-17 18:43:24.691: E/AndroidRuntime(5171): at java.util.ArrayList.get(ArrayList.java:304)

10-17 18:43:24.691: E/AndroidRuntime(5171): at com.yabeat.skipmp3.ui.YBTShopHomeActivity.updateViewPagerIndex(YBTShopHomeActivity.java:332)

10-17 18:43:24.691: E/AndroidRuntime(5171): at com.yabeat.skipmp3.ui.YBTShopHomeActivity.updateViewPager(YBTShopHomeActivity.java:321)

10-17 18:43:24.691: E/AndroidRuntime(5171): at com.yabeat.skipmp3.ui.YBTShopHomeActivity.createLargeFragments(YBTShopHomeActivity.java:347)

10-17 18:43:24.691: E/AndroidRuntime(5171): at com.yabeat.skipmp3.ui.YBTShopHomeActivity.onCreate(YBTShopHomeActivity.java:402)

10-17 18:43:24.691: E/AndroidRuntime(5171): at android.app.Activity.performCreate(Activity.java:5008)

10-17 18:43:24.691: E/AndroidRuntime(5171): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)

10-17 18:43:24.691: E/AndroidRuntime(5171): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)

mSmallFragments = new ArrayList();

Problem is, that the app works on smartphone perfectly (4.1.2), but crashes on tablet (4.1.1).

If I remove: ((android.support.v4.view.ViewPager.OnPageChangeListener)mSmallFragments.get(j)).onPageSelected(j);,

the app starts but doesn't show any ArrayList (only the main layout of the app).

分享给朋友:
您可能感兴趣的文章:
随机阅读: