开发过程称遇到各种错误,很少头疼,下面贴下我遇到的错误:
java.lang.IllegalArgumentException: Binary XML file line #676: Duplicate id 0x7f0f02a6, tag null, or parent id 0xffffffff with another fragment for com.example.yuanmu.lunbo.Custom.CycleViewPager
这个说的是我引入的布局的ID重复了,所以报错,下面贴日志:
03-28 10:28:56.540 18903-18903/? E/AndroidRuntime: FATAL EXCEPTION: main
Process:
com.example.yuanmu.lunbo, PID: 18903
android.view.InflateException:
Binary XML file line #676: Error inflating class fragment
at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:769)
at
android.view.LayoutInflater.rInflate(LayoutInflater.java:812)
at
android.view.LayoutInflater.rInflate(LayoutInflater.java:815)
at
android.view.LayoutInflater.rInflate(LayoutInflater.java:815)
at
android.view.LayoutInflater.rInflate(LayoutInflater.java:815)
at
android.view.LayoutInflater.inflate(LayoutInflater.java:510)
at
android.view.LayoutInflater.inflate(LayoutInflater.java:420)
at
com.example.yuanmu.lunbo.Fragment.RankingFragment.onCreateView
(RankingFragment.java:72)
at
android.support.v4.app.Fragment.performCreateView(Fragment.java:2074)
at
android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
at
android.support.v4.app.FragmentManagerImpl.attachFragment
(FragmentManager.java:1464)
at
android.support.v4.app.BackStackRecord.run(BackStackRecord.java:748)
at
android.support.v4.app.FragmentManagerImpl.execSingleAction
(FragmentManager.java:1632)
at
android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss
(BackStackRecord.java:637)
at
android.support.v4.app.FragmentPagerAdapter.finishUpdate
(FragmentPagerAdapter.java:143)
at
android.support.v4.view.ViewPager.populate(ViewPager.java:1235)
at
android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:666)
at
android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:628)
at
android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:609)
at
com.example.yuanmu.lunbo.Fragment.CircleFragment$1.onTabSelect
(CircleFragment.java:50)
at
com.example.yuanmu.lunbo.Custom.LifeCircleMainTitleView$1.onClick
(LifeCircleMainTitleView.java:99)
at
android.view.View.performClick(View.java:4909)
at android.view.View
$PerformClick.run(View.java:20390)
at
android.os.Handler.handleCallback(Handler.java:815)
at
android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop
(Looper.java:194)
at
android.app.ActivityThread.main(ActivityThread.java:5860)
at
java.lang.reflect.Method.invoke(Native Method)
at
java.lang.reflect.Method.invoke(Method.java:372)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1019)
at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:814)
Caused by:
java.lang.IllegalArgumentException: Binary XML file line #676: Duplicate id
0x7f0f02a6, tag null, or parent id 0xffffffff with another fragment for
com.example.yuanmu.lunbo.Custom.CycleViewPager
at
android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2416)
at
android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
at
android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView
(FragmentActivity.java:374)
at
android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView
(BaseFragmentActivityHoneycomb.java:33)
at
android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:75)
at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:739)
at
android.view.LayoutInflater.rInflate(LayoutInflater.java:812)
at
android.view.LayoutInflater.rInflate(LayoutInflater.java:815)
at
android.view.LayoutInflater.rInflate(LayoutInflater.java:815)
at
android.view.LayoutInflater.rInflate(LayoutInflater.java:815)
at
android.view.LayoutInflater.inflate(LayoutInflater.java:510)
at
android.view.LayoutInflater.inflate(LayoutInflater.java:420)
at
com.example.yuanmu.lunbo.Fragment.RankingFragment.onCreateView
(RankingFragment.java:72)
at
android.support.v4.app.Fragment.performCreateView(Fragment.java:2074)
at
android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
at
android.support.v4.app.FragmentManagerImpl.attachFragment
(FragmentManager.java:1464)
at
android.support.v4.app.BackStackRecord.run(BackStackRecord.java:748)
at
android.support.v4.app.FragmentManagerImpl.execSingleAction
(FragmentManager.java:1632)
at
android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss
(BackStackRecord.java:637)
at
android.support.v4.app.FragmentPagerAdapter.finishUpdate
(FragmentPagerAdapter.java:143)
at
android.support.v4.view.ViewPager.populate(ViewPager.java:1235)
at
android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:666)
at
android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:628)
at
android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:609)
at
com.example.yuanmu.lunbo.Fragment.CircleFragment$1.onTabSelect
(CircleFragment.java:50)
at
com.example.yuanmu.lunbo.Custom.LifeCircleMainTitleView$1.onClick
(LifeCircleMainTitleView.java:99)
at
android.view.View.performClick(View.java:4909)
at android.view.View
$PerformClick.run(View.java:20390)
at
android.os.Handler.handleCallback(Handler.java:815)
at
android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop
(Looper.java:194)
at
android.app.ActivityThread.main(ActivityThread.java:5860) at
java.lang.reflect.Method.invoke(Native Method) at
java.lang.reflect.Method.invoke(Method.java:372)
at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1019) at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:814)
03-28 10:29:36.504 18046-18046/? I/AndroidRuntime: VM exiting with result code 0,
cleanup skipped.
03-28 10:29:56.778 17400-17400/? I/AndroidRuntime: VM exiting with result code 0,
cleanup skipped.
03-28 10:36:12.023 19647-19647/? I/AndroidRuntime: VM exiting with result code 0,
cleanup skipped.
03-28 10:37:49.565 21731-21731/? I/AndroidRuntime: VM exiting with result code 0,
cleanup skipped.
下面是我的部分代码:
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mContext = container.getContext();
view = (ViewGroup) inflater.from(mContext).inflate(R.layout.lifecircle_ranking_fragment, container, false);
return view;
}
我的布局是Fragment再添加个Fragment,也就是Fragment里有轮播图,轮播放也是用Fragment做的
看了错误日志,可以这样改:
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
mContext = container.getContext();
//view不为空时才加载布局,不然会重复的ID,报错
view = (ViewGroup) inflater.from(mContext).inflate(R.layout.lifecircle_ranking_fragment, container, false);
if (view == null) {
view = (ViewGroup) inflater.from(mContext).inflate(R.layout.lifecircle_ranking_fragment, container, false);
//轮播图
initialize();
}
---------------------
[C#] 纯文本查看 复制代码 return view;
}
这样就不会报错了
|
|