title: java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams cannot be cast to android.support.v7.widget.RecyclerView$LayoutParams
body: <p>I have a RecyclerView with a LinearLayout inside. The LinearLayout consists out of 9 buttons. Before some changes I could click the buttons and it didn't crashed. But after I added this code below it gives the error and does not show where it comes from:</p>
  
  <blockquote>
    <p>java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams
    cannot be cast to android.support.v7.widget.RecyclerView$LayoutParams</p>
  </blockquote>
  
  <p>The imports in Adapter:</p>
  
  <pre><code>    import android.content.Context;
  import android.graphics.Color;
  import android.support.v7.widget.RecyclerView;
  import android.widget.LinearLayout.LayoutParams;
  import android.util.TypedValue;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.Button;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  </code></pre>
  
  <p>Added this in the onClickListener:</p>
  
  <pre><code>tempTag = (int) v.getTag();
  mAdapter.grayButton(tempTag / 9, tempTag % 9);
  zahl1 = Integer.parseInt(mAdapter.getText(tempTag).toString());
  </code></pre>
  
  <p>Added this method in the RecyclerView.Adapter:</p>
  
  <pre><code>    public void grayButton(int row, int element){
      recycleViewDatas.get(row).setGray(element);
      notifyItemChanged(row);
  }
  </code></pre>
  
  <p>Added this code in the onBindViewHolder:</p>
  
  <pre><code>LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
  viewHolder.ll.setLayoutParams(lp);
  lp.height = viewHolder.ll.getLayoutParams().height - (int) (viewHolder.buttons.get(j).getLayoutParams().height - recycleViewDatas.get(i).getSize()) + 30;
  viewHolder.ll.setLayoutParams(lp);
  if(recycleViewDatas.get(i).getGray() == j)
       viewHolder.buttons.get(j).setTextColor(Color.GRAY);
  else if(recycleViewDatas.get(i).getGray() == -1)
       viewHolder.buttons.get(j).setTextColor(Color.BLACK);
  </code></pre>
  
  <p>This is my ViewHolder:</p>
  
  <pre><code>public static class ViewHolder extends RecyclerView.ViewHolder {
      LinearLayout ll;
      private ArrayList&lt;Button&gt; buttons = new ArrayList&lt;&gt;();
  
      public ViewHolder(View v, Context context) {
          super(v);
  
          ll = (LinearLayout) v.findViewById(R.id.llRecycleView);
          for (int i = 0; i &lt; ll.getChildCount(); i++) {
              buttons.add((Button) ll.getChildAt(i));
          }
      }
  }
  </code></pre>
  
  <p>The layout file of the recycleviewdata:</p>
  
  <pre><code>&lt;LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="horizontal"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:weightSum="9"
  android:background="@drawable/zeile"
  android:id="@+id/llRecycleView"&gt;
  
  &lt;Button
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_weight="1"
      android:textColor="@android:color/black"
      android:background="@android:color/transparent"
      android:textSize="23sp"
      android:clickable="false"
      android:layout_gravity="center"
      android:gravity="center" /&gt;
  </code></pre>
  
  <p>...more buttons</p>
  
  <p>The layout of the MainActivity:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent"&gt;
  
  &lt;LinearLayout
      android:orientation="vertical"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:weightSum="2"
      android:background="@drawable/top"&gt;
  ...some buttons
  &lt;/LinearLayout&gt;
  
  &lt;android.support.v7.widget.RecyclerView
      android:id="@+id/my_recycler_view"
      android:scrollbars="vertical"
      android:layout_width="match_parent"
      android:layout_height="match_parent"/&gt;&lt;/LinearLayout&gt;
  </code></pre>
  
  <p>I do not understand why the error comes after the update. And the app only crashes on my M9. On the HTC One V it does not crash and all works as expected.
  You know the problem? Do you need any more code?</p>