为什么会出现此异常?java.lang.IllegalStateException

时间:2016-06-21 04:18:25

标签: android android-fragments

我的代码:

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_one, container, false);
        RecyclerView recyclerView = (RecyclerView)view.findViewById(R.id.recyclerView);
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(mAdapter);
        return view;
    }

例外:

  

java.lang.IllegalStateException:指定的子节点已经有了   家长。您必须首先在孩子的父母上调用removeView()。                                                                                        在android.view.ViewGroup.addViewInner(ViewGroup.java:3509)                                                                                        在android.view.ViewGroup.addView(ViewGroup.java:3380)                                                                                        在android.view.ViewGroup.addView(ViewGroup.java:3325)                                                                                        在   android.support.v7.widget.RecyclerView $ 5.addView(RecyclerView.java:591)                                                                                        在android.support.v7.widget.ChildHelper.addView(ChildHelper.java:107)                                                                                        在   android.support.v7.widget.RecyclerView $ LayoutManager.addViewInt(RecyclerView.java:6695)                                                                                        在   android.support.v7.widget.RecyclerView $ LayoutManager.addView(RecyclerView.java:6653)                                                                                        在   android.support.v7.widget.RecyclerView $ LayoutManager.addView(RecyclerView.java:6641)                                                                                        在   android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1398)                                                                                        在   android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1347)                                                                                        在   android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:574)                                                                                        在   android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3003)                                                                                        在   android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2881)                                                                                        在   android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3265)                                                                                        在android.view.View.layout(View.java:14471)                                                                                        在android.view.ViewGroup.layout(ViewGroup.java:4562)                                                                                        在android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076)                                                                                        在android.view.View.layout(View.java:14471)                                                                                        在android.view.ViewGroup.layout(ViewGroup.java:4562)                                                                                        在android.support.v4.view.ViewPager.onLayout(ViewPager.java:1695)                                                                                        在android.view.View.layout(View.java:14471)                                                                                        在android.view.ViewGroup.layout(ViewGroup.java:4562)                                                                                        在   android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:122)                                                                                        在   android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42)                                                                                        在   android.support.design.widget.AppBarLayout $ ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1149)                                                                                        在   android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:810)                                                                                        在android.view.View.layout(View.java:14471)                                                                                        在android.view.ViewGroup.layout(ViewGroup.java:4562)                                                                                        在android.widget.FrameLayout.onLayout(FrameLayout.java:448)                                                                                        在android.view.View.layout(View.java:14471)                                                                                        在android.view.ViewGroup.layout(ViewGroup.java:4562)                                                                                        在android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)                                                                                        在android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)                                                                                        在android.widget.LinearLayout.onLayout(LinearLayout.java:1434)                                                                                        在android.view.View.layout(View.java:14471)                                                                                        在android.view.ViewGroup.layout(ViewGroup.java:4562)                                                                                        在android.widget.FrameLayout.onLayout(FrameLayout.java:448)                                                                                        在android.view.View.layout(View.java:14471)                                                                                        在android.view.ViewGroup.layout(ViewGroup.java:4562)                                                                                        在android.widget.LinearLayout.setChildFrame(LinearLayout.java:1671)                                                                                        在android.widget.LinearLayout.layoutVertical(LinearLayout.java:1525)                                                                                        在android.widget.LinearLayout.onLayout(LinearLayout.java:1434)                                                                                        在android.view.View.layout(View.java:14471)                                                                                        在android.view.ViewGroup.layout(ViewGroup.java:4562)                                                                                        在android.widget.FrameLayout.onLayout(FrameLayout.java:448)                                                                                        在android.view.View.layout(View.java:14471)                                                                                        在android.view.ViewGroup.layout(ViewGroup.java:4562)                                                                                        在android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1984)                                                                                        在android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1738)                                                                                        在android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1008)                                                                                        在   android.view.ViewRootImpl $ TraversalRunnable.run(ViewRootImpl.java:5509)                                                                                        在   android.view.Choreographer $ CallbackRecord.run(Choreographer.java:749)                                                                                        在android.view.Choreographer.doCallbacks(Choreographer.java:562)                                                                                        在android.view.Choreographer.doFrame(Choreographer.java:532)                                                                                        在   android.view.Choreographer $ FrameDisplayEventReceiver.run(Choreographer.java:735)                                                                                        在android.os.Handler.handleCallback(Handler.java:730)                                                                                        在android.os.Handler.dispatchMessage(Handler.java:92)                                                                                        在android.os.Looper.loop(Looper.java:137)                                                                                     在android.app.Acti

0 个答案:

没有答案