ViewGroup.layout() has thrown an IllegalStateException

java.lang.IllegalStateException
Javadoc
Signals that a method has been invoked at an illegal or inappropriate time. In other words, the Java environment or Java application is not in an appropriate state for the requested operation. @author Jonni Kanerva @since JDK1.1
at android.support.v7.widget.RecyclerView$LayoutManager.addViewInt
(source)
at android.support.v7.widget.RecyclerView$LayoutManager.addView
(source)
at android.support.v7.widget.RecyclerView$LayoutManager.addView
(source)
at android.support.v7.widget.LinearLayoutManager.layoutChunk
(source)
at android.support.v7.widget.LinearLayoutManager.fill
(source)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren
(source)
at android.support.v7.widget.RecyclerView.dispatchLayout
(source)
at android.support.v7.widget.RecyclerView.onLayout
(source)
at android.view.View.layout
(source)
at android.view.ViewGroup.layout
(source)
9 frames hidden

Typical Exception Messages

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

Origin

RecyclerView.dispatchLayout() has thrown an IllegalStateException

java.lang.IllegalStateException
6 frames hidden
android.support.v7.widget.RecyclerView.dispatchLayout
2Web pages

Solution

Larten, 1 year ago

You should use View v = inflater.inflate(R.layout.your_layout, parent, false);

instead of View v = inflater.inflate(R.layout.your_layout, parent, true);

External results for this pattern (2)

  1. hush881025via GitHub4 months ago
    Added View has RecyclerView as parent but view is not a real child. Unfiltered index:0
    Show stack trace
  2. wliu6vvia GitHub7 months ago
    Added View has RecyclerView as parent but view is not a real child. Unfiltered index:0
    Show stack trace