question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

java.lang.IllegalStateException: Added View has RecyclerView as parent but view is not a real child. Unfiltered index:0

See original GitHub issue

Hi, I use expandable and draggable adapter in my app. Some users crashed when use my app, but I can’t response this crash.

Here’s the crash log, I want to know if there’s any other people has this crash? And how to solve it?

java.lang.IllegalStateException: Added View has RecyclerView as parent but view is not a real child. Unfiltered index:0
    at android.support.v7.widget.RecyclerView$LayoutManager.addViewInt(RecyclerView.java:6071)
    at android.support.v7.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:6037)
    at android.support.v7.widget.RecyclerView$LayoutManager.addView(RecyclerView.java:6025)
    at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1378)
    at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1327)
    at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:556)
    at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2713)
    at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:3011)
    at android.view.View.layout(View.java:14858)
    at android.view.ViewGroup.layout(ViewGroup.java:4646)
    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1673)
    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1527)
    at android.widget.LinearLayout.onLayout(LinearLayout.java:1436)
    at android.view.View.layout(View.java:14858)
    at android.view.ViewGroup.layout(ViewGroup.java:4646)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
    at android.view.View.layout(View.java:14858)
    at android.view.ViewGroup.layout(ViewGroup.java:4646)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
    at android.view.View.layout(View.java:14858)
    at android.view.ViewGroup.layout(ViewGroup.java:4646)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
    at android.view.View.layout(View.java:14858)
    at android.view.ViewGroup.layout(ViewGroup.java:4646)
    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1673)
    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1527)
    at android.widget.LinearLayout.onLayout(LinearLayout.java:1436)
    at android.view.View.layout(View.java:14858)
    at android.view.ViewGroup.layout(ViewGroup.java:4646)
    at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
    at android.view.View.layout(View.java:14858)
    at android.view.ViewGroup.layout(ViewGroup.java:4646)
    at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2035)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1792)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1047)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5896)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
    at android.view.Choreographer.doCallbacks(Choreographer.java:574)
    at android.view.Choreographer.doFrame(Choreographer.java:544)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5103)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
    at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
    at dalvik.system.NativeStart.main(Native Method)

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
crazymajaxcommented, Mar 2, 2016

I had the same error and the solution for me was to no longer specify my own ids. So I removed the following lines of code and it started working again:

  public MyAdapter(Context context) {
      this.context = context;
-     setHasStableIds(true)   // <----- removed this
  }

and all of this:

 -    @Override     
 -    public long getItemId(int position) {     
 -        return position;      
 -    }
1reaction
GauthierChancommented, Dec 15, 2015

I had the same error when using the Swipe adapter and removing/adding elements. It was related to duplicate IDs given to items. (2 items had the same ID, if I clicked on the second item -> crash).

Once I made sure every IDs were unique everything worked fine.

Hope it helps you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Added View has RecyclerView as parent but view is not a real ...
I have an issue appears sometimes when content of RecyclerView is changes. I have search view that filters data of RecyclerView. After filtering...
Read more >
v7/recyclerview/src/android/support/v7/widget ... - Google Git
from the parent RecyclerView, either unmodified if no rebinding is required or modified. * by the adapter if the view was considered <em>dirty</em>.</li>....
Read more >
UltimateRecyclerView - Bountysource
java.lang.IllegalStateException: Added View has RecyclerView as parent but view is not a real child. Unfiltered index:0 $ 0.
Read more >
Using the RecyclerView | CodePath Android Cliffnotes
The RecyclerView is a ViewGroup that renders any adapter-based view in a similar way. It is supposed to be the successor of ListView...
Read more >
Source Code for RecyclerView.java - AndroidX Tech
</li> * <li><em>Scrap (view):</em> A child view that has entered into a ... RecyclerView will clip its children to its padding, and resize...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found