gpt4 book ai didi

android - ViewPager FragmentPagerAdapter Nullpointer

转载 作者:IT老高 更新时间:2023-10-28 21:39:10 24 4
gpt4 key购买 nike

我在 Android Support package 中使用 ViewPager 时遇到此错误.从水平 View 使用 ViewPager Tutorial 滑动

06-19 13:07:25.950: E/AndroidRuntime(16382): FATAL EXCEPTION: main
06-19 13:07:25.950: E/AndroidRuntime(16382): java.lang.NullPointerException
06-19 13:07:25.950: E/AndroidRuntime(16382): at android.support.v4.app.BackStackRecord.doAddOp(BackStackRecord.java:347)
06-19 13:07:25.950: E/AndroidRuntime(16382): at android.support.v4.app.BackStackRecord.add(BackStackRecord.java:342)
06-19 13:07:25.950: E/AndroidRuntime(16382): at android.support.v4.app.FragmentPagerAdapter.instantiateItem(FragmentPagerAdapter.java:97)
06-19 13:07:25.950: E/AndroidRuntime(16382): at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:649)
06-19 13:07:25.950: E/AndroidRuntime(16382): at android.support.v4.view.ViewPager.populate(ViewPager.java:783)
06-19 13:07:25.950: E/AndroidRuntime(16382): at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1016)
06-19 13:07:25.950: E/AndroidRuntime(16382): at android.view.View.measure(View.java:12728)
06-19 13:07:25.950: E/AndroidRuntime(16382): at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:594)
06-19 13:07:25.950: E/AndroidRuntime(16382): at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:376)
06-19 13:07:25.950: E/AndroidRuntime(16382): at android.view.View.measure(View.java:12728)
06-19 13:07:25.950: E/AndroidRuntime(16382): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
06-19 13:07:25.950: E/AndroidRuntime(16382): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
06-19 13:07:25.950: E/AndroidRuntime(16382): at android.view.View.measure(View.java:12728)
06-19 13:07:25.950: E/AndroidRuntime(16382): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
06-19 13:07:25.950: E/AndroidRuntime(16382): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1369)
06-19 13:07:25.950: E/AndroidRuntime(16382): at android.widget.LinearLayout.measureVertical(LinearLayout.java:660)
06-19 13:07:25.950: E/AndroidRuntime(16382): at android.widget.LinearLayout.onMeasure(LinearLayout.java:553)
06-19 13:07:25.950: E/AndroidRuntime(16382): at android.view.View.measure(View.java:12728)
06-19 13:07:25.950: E/AndroidRuntime(16382): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4698)
06-19 13:07:25.950: E/AndroidRuntime(16382): at android.widget.FrameLayout.onMeasure(FrameLayout.java:293)
06-19 13:07:25.950: E/AndroidRuntime(16382): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2092)
06-19 13:07:25.950: E/AndroidRuntime(16382): at android.view.View.measure(View.java:12728)
06-19 13:07:25.950: E/AndroidRuntime(16382): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1064)
06-19 13:07:25.950: E/AndroidRuntime(16382): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
06-19 13:07:25.950: E/AndroidRuntime(16382): at android.os.Handler.dispatchMessage(Handler.java:99)
06-19 13:07:25.950: E/AndroidRuntime(16382): at android.os.Looper.loop(Looper.java:137)
06-19 13:07:25.950: E/AndroidRuntime(16382): at android.app.ActivityThread.main(ActivityThread.java:4424)
06-19 13:07:25.950: E/AndroidRuntime(16382): at java.lang.reflect.Method.invokeNative(Native Method)
06-19 13:07:25.950: E/AndroidRuntime(16382): at java.lang.reflect.Method.invoke(Method.java:511)
06-19 13:07:25.950: E/AndroidRuntime(16382): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
06-19 13:07:25.950: E/AndroidRuntime(16382): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
06-19 13:07:25.950: E/AndroidRuntime(16382): at dalvik.system.NativeStart.main(Native Method)

最佳答案

以防万一有人没有阅读 passsy 答案的评论,这里是有用答案的摘要:

1) 非常仔细地检查您的 getItem(int index) 方法,并寻找任何可能导致您以 null fragment 。

2) 检查 getCount() 返回的计数是否与 getItem(int index) 中返回的 fragment 数匹配。

3) 检查您的导入并确保您没有将 android.app.Fragmentandroid.support.v4.app.Fragment

混用

关于android - ViewPager FragmentPagerAdapter Nullpointer,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11099897/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com