1

我的 android 应用程序中的以下命令有问题:

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

我得到:

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();

问题是,该应用程序在智能手机上完美运行(4.1.2),但在平板电脑(4.1.1)上崩溃。

如果我删除:((android.support.v4.view.ViewPager.OnPageChangeListener)mSmallFragments.get(j)).onPageSelected(j);

应用程序启动但不显示任何 ArrayList(仅应用程序的主布局)。

4

0 回答 0