title: androidx.recyclerview.widget.RecyclerView cannot be cast to android.widget.LinearLayout
body: <p>When I click <strong>Update Faculty</strong> (MaterialCardView) in the activity_main.xml the activity activity_update_faculty.xml suppose to display but my app crashes and closes, I tried to find the problem in the logcat and it says &quot;androidx.recyclerview.widget.RecyclerView cannot be cast to android.widget.LinearLayout&quot; I'm struggling to find the problem since I'm still new. Can someone help me, please</p>
  <p>Here's is the activity_main.xml :</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;LinearLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      android:orientation=&quot;vertical&quot;
      tools:context=&quot;.MainActivity&quot;&gt;
      &lt;LinearLayout
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_margin=&quot;5dp&quot;
          android:gravity=&quot;center&quot;
          android:orientation=&quot;horizontal&quot;&gt;
          &lt;com.google.android.material.card.MaterialCardView
              android:id=&quot;@+id/addNotice&quot;
              android:layout_width=&quot;130dp&quot;
              android:layout_height=&quot;150dp&quot;
              android:layout_margin=&quot;10dp&quot;
              app:cardElevation=&quot;5dp&quot;&gt;
  
              &lt;LinearLayout
                  android:layout_width=&quot;135dp&quot;
                  android:layout_height=&quot;match_parent&quot;
                  android:gravity=&quot;center&quot;
                  android:orientation=&quot;vertical&quot;&gt;
  
                  &lt;ImageView
                      android:layout_width=&quot;64dp&quot;
                      android:layout_height=&quot;64dp&quot;
                      android:background=&quot;@drawable/circle_green&quot;
                      android:padding=&quot;15dp&quot;
                      android:src=&quot;@drawable/ic_notice&quot; /&gt;
  
                  &lt;View
                      android:layout_width=&quot;match_parent&quot;
                      android:layout_height=&quot;1dp&quot;
                      android:layout_marginTop=&quot;10dp&quot;
                      android:background=&quot;@color/lightGray&quot; /&gt;
  
                  &lt;TextView
                      android:layout_width=&quot;wrap_content&quot;
                      android:layout_height=&quot;wrap_content&quot;
                      android:layout_marginTop=&quot;10dp&quot;
                      android:padding=&quot;5dp&quot;
                      android:text=&quot;Upload Notice&quot;
                      android:textColor=&quot;@color/textColor&quot;
                      android:textStyle=&quot;bold&quot; /&gt;
  
  
              &lt;/LinearLayout&gt;
          &lt;/com.google.android.material.card.MaterialCardView&gt;
  
          &lt;com.google.android.material.card.MaterialCardView
              android:id=&quot;@+id/addGalleryImage&quot;
              android:layout_width=&quot;130dp&quot;
              android:layout_height=&quot;150dp&quot;
              android:layout_margin=&quot;10dp&quot;
              app:cardElevation=&quot;5dp&quot;&gt;
              &lt;LinearLayout
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;match_parent&quot;
                  android:gravity=&quot;center&quot;
                  android:orientation=&quot;vertical&quot;&gt;
                  &lt;ImageView
                      android:layout_width=&quot;64dp&quot;
                      android:layout_height=&quot;64dp&quot;
                      android:background=&quot;@drawable/circle_purple&quot;
                      android:padding=&quot;15dp&quot;
                      android:src=&quot;@drawable/ic_gallery&quot;/&gt;
                  &lt;View
                      android:layout_width=&quot;match_parent&quot;
                      android:layout_height=&quot;1dp&quot;
                      android:layout_marginTop=&quot;10dp&quot;
                      android:background=&quot;@color/lightGray&quot;/&gt;
                  &lt;TextView
                      android:layout_width=&quot;wrap_content&quot;
                      android:layout_height=&quot;wrap_content&quot;
                      android:layout_marginTop=&quot;10dp&quot;
                      android:padding=&quot;5dp&quot;
                      android:text=&quot;Upload Image&quot;
                      android:textColor=&quot;@color/textColor&quot;
                      android:textStyle=&quot;bold&quot;/&gt;
  
  
              &lt;/LinearLayout&gt;
          &lt;/com.google.android.material.card.MaterialCardView&gt;
  
  
  
      &lt;/LinearLayout&gt;
      &lt;LinearLayout
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_margin=&quot;5dp&quot;
          android:gravity=&quot;center&quot;
          android:orientation=&quot;horizontal&quot;&gt;
          &lt;com.google.android.material.card.MaterialCardView
              android:id=&quot;@+id/addEbook&quot;
              android:layout_width=&quot;130dp&quot;
              android:layout_height=&quot;150dp&quot;
              android:layout_margin=&quot;10dp&quot;
              app:cardElevation=&quot;5dp&quot;&gt;
              &lt;LinearLayout
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;match_parent&quot;
                  android:gravity=&quot;center&quot;
                  android:orientation=&quot;vertical&quot;&gt;
                  &lt;ImageView
                      android:layout_width=&quot;64dp&quot;
                      android:layout_height=&quot;64dp&quot;
                      android:background=&quot;@drawable/circle_pink&quot;
                      android:padding=&quot;15dp&quot;
                      android:src=&quot;@drawable/ic_upload&quot;/&gt;
                  &lt;View
                      android:layout_width=&quot;match_parent&quot;
                      android:layout_height=&quot;1dp&quot;
                      android:layout_marginTop=&quot;10dp&quot;
                      android:background=&quot;@color/lightGray&quot;/&gt;
                  &lt;TextView
                      android:layout_width=&quot;wrap_content&quot;
                      android:layout_height=&quot;wrap_content&quot;
                      android:layout_marginTop=&quot;10dp&quot;
                      android:padding=&quot;5dp&quot;
                      android:text=&quot;Upload Ebook&quot;
                      android:textColor=&quot;@color/textColor&quot;
                      android:textStyle=&quot;bold&quot;/&gt;
  
  
              &lt;/LinearLayout&gt;
          &lt;/com.google.android.material.card.MaterialCardView&gt;
  
          &lt;com.google.android.material.card.MaterialCardView
              android:id=&quot;@+id/faculty&quot;
              android:layout_width=&quot;130dp&quot;
              android:layout_height=&quot;150dp&quot;
              android:layout_margin=&quot;10dp&quot;
              app:cardElevation=&quot;5dp&quot;&gt;
              &lt;LinearLayout
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;match_parent&quot;
                  android:gravity=&quot;center&quot;
                  android:orientation=&quot;vertical&quot;&gt;
                  &lt;ImageView
                      android:layout_width=&quot;64dp&quot;
                      android:layout_height=&quot;64dp&quot;
                      android:background=&quot;@drawable/circle_yellow&quot;
                      android:padding=&quot;15dp&quot;
                      android:src=&quot;@drawable/ic_group&quot;/&gt;
                  &lt;View
                      android:layout_width=&quot;match_parent&quot;
                      android:layout_height=&quot;1dp&quot;
                      android:layout_marginTop=&quot;10dp&quot;
                      android:background=&quot;@color/lightGray&quot;/&gt;
                  &lt;TextView
                      android:layout_width=&quot;wrap_content&quot;
                      android:layout_height=&quot;wrap_content&quot;
                      android:layout_marginTop=&quot;10dp&quot;
                      android:padding=&quot;5dp&quot;
                      android:text=&quot;Update Faculty&quot;
                      android:textColor=&quot;@color/textColor&quot;
                      android:textStyle=&quot;bold&quot;/&gt;
  
  
              &lt;/LinearLayout&gt;
          &lt;/com.google.android.material.card.MaterialCardView&gt;
  
  
  
      &lt;/LinearLayout&gt;
      &lt;LinearLayout
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_margin=&quot;5dp&quot;
          android:gravity=&quot;center&quot;
          android:orientation=&quot;horizontal&quot;&gt;
          &lt;com.google.android.material.card.MaterialCardView
              android:id=&quot;@+id/deleteNotice&quot;
              android:layout_width=&quot;130dp&quot;
              android:layout_height=&quot;150dp&quot;
              android:layout_margin=&quot;10dp&quot;
              app:cardElevation=&quot;5dp&quot;&gt;
              &lt;LinearLayout
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;match_parent&quot;
                  android:gravity=&quot;center&quot;
                  android:orientation=&quot;vertical&quot;&gt;
                  &lt;ImageView
                      android:layout_width=&quot;64dp&quot;
                      android:layout_height=&quot;64dp&quot;
                      android:background=&quot;@drawable/cicle_red&quot;
                      android:padding=&quot;15dp&quot;
                      android:src=&quot;@drawable/ic_delete&quot;/&gt;
                  &lt;View
                      android:layout_width=&quot;match_parent&quot;
                      android:layout_height=&quot;1dp&quot;
                      android:layout_marginTop=&quot;10dp&quot;
                      android:background=&quot;@color/lightGray&quot;/&gt;
                  &lt;TextView
                      android:layout_width=&quot;wrap_content&quot;
                      android:layout_height=&quot;wrap_content&quot;
                      android:layout_marginTop=&quot;10dp&quot;
                      android:padding=&quot;5dp&quot;
                      android:text=&quot;Delete Notice&quot;
                      android:textColor=&quot;@color/textColor&quot;
                      android:textStyle=&quot;bold&quot;/&gt;
  
  
              &lt;/LinearLayout&gt;
          &lt;/com.google.android.material.card.MaterialCardView&gt;
  
  
  
  
  
      &lt;/LinearLayout&gt;
  
  
  
  &lt;/LinearLayout&gt;
  </code></pre>
  <p>Here is the MainActivity.java :</p>
  <pre><code>package com.example.adminuniversityapp;
  
  import androidx.appcompat.app.AppCompatActivity;
  import androidx.cardview.widget.CardView;
  
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  
  import com.example.adminuniversityapp.facculty.UpdateFaculty;
  
  public class MainActivity extends AppCompatActivity implements View.OnClickListener {
  
      CardView uploadNptice, addGalleryImage, addEbook, faculty;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
  
          uploadNptice = findViewById(R.id.addNotice);
          addGalleryImage = findViewById(R.id.addGalleryImage);
          addEbook = findViewById(R.id.addEbook);
          faculty = findViewById(R.id.faculty);
  
          uploadNptice.setOnClickListener(this);
          addGalleryImage.setOnClickListener(this);
          addEbook.setOnClickListener(this);
          faculty.setOnClickListener(this);
      }
  
      @Override
      public void onClick(View v) {
          Intent intent;
          switch (v.getId()){
              case R.id.addNotice:
                   intent = new Intent( MainActivity.this,UploadNotice.class);
                   startActivity(intent);
                   break;
  
              case R.id.addGalleryImage:
                   intent = new Intent( MainActivity.this,UploadImage.class);
                   startActivity(intent);
                   break;
              case R.id.addEbook:
                  intent = new Intent( MainActivity.this,UploadPdfActivity.class);
                  startActivity(intent);
                  break;
              case R.id.faculty:
                  intent = new Intent( MainActivity.this, UpdateFaculty.class);
                  startActivity(intent);
                  break;
          }
  
  
      }
  }
  </code></pre>
  <p>activity_update_faculty.xml :</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;
  &lt;androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android=&quot;http://schemas.android.com/apk/res/android&quot;
      xmlns:app=&quot;http://schemas.android.com/apk/res-auto&quot;
      xmlns:tools=&quot;http://schemas.android.com/tools&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;match_parent&quot;
      tools:context=&quot;.facculty.UpdateFaculty&quot;&gt;
  
      &lt;com.google.android.material.floatingactionbutton.FloatingActionButton
          android:id=&quot;@+id/fab&quot;
          style=&quot;@style/Widget.Design.FloatingActionButton&quot;
          android:layout_width=&quot;wrap_content&quot;
          android:layout_height=&quot;wrap_content&quot;
          android:layout_gravity=&quot;bottom|right&quot;
          android:layout_margin=&quot;16dp&quot;
          android:src=&quot;@drawable/ic_add&quot;
          app:elevation=&quot;3dp&quot;
          app:fabSize=&quot;normal&quot;/&gt;
  
      &lt;androidx.core.widget.NestedScrollView
          android:layout_width=&quot;match_parent&quot;
          android:layout_height=&quot;match_parent&quot;&gt;
  
          &lt;LinearLayout
              android:layout_width=&quot;match_parent&quot;
              android:layout_height=&quot;match_parent&quot;
              android:orientation=&quot;vertical&quot;&gt;
  
              &lt;TextView
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_marginTop=&quot;16dp&quot;
                  android:gravity=&quot;center&quot;
                  android:text=&quot;Computer Science&quot;
                  android:textColor=&quot;@color/textColor&quot;
                  android:textSize=&quot;22sp&quot;
                  android:textStyle=&quot;bold&quot;/&gt;
  
              &lt;View
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;1dp&quot;
                  android:layout_marginVertical=&quot;8dp&quot;
                  android:background=&quot;#c1c1c1&quot;/&gt;
  
              &lt;androidx.recyclerview.widget.RecyclerView
                  android:id=&quot;@+id/csDepartment&quot;
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:nestedScrollingEnabled=&quot;false&quot;
                  android:visibility=&quot;gone&quot;/&gt;
  
              &lt;LinearLayout
                  android:id=&quot;@+id/csNoData&quot;
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:orientation=&quot;vertical&quot;&gt;
  
                  &lt;include layout=&quot;@layout/no_data_found&quot;/&gt;
  
              &lt;/LinearLayout&gt;
  
  
              &lt;TextView
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_marginTop=&quot;16dp&quot;
                  android:gravity=&quot;center&quot;
                  android:text=&quot;Mechanical Engineering&quot;
                  android:textColor=&quot;@color/textColor&quot;
                  android:textSize=&quot;22sp&quot;
                  android:textStyle=&quot;bold&quot;/&gt;
  
              &lt;View
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;1dp&quot;
                  android:layout_marginVertical=&quot;8dp&quot;
                  android:background=&quot;#c1c1c1&quot;/&gt;
  
              &lt;androidx.recyclerview.widget.RecyclerView
                  android:id=&quot;@+id/mechanicalDepartment&quot;
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:nestedScrollingEnabled=&quot;false&quot;
                  android:visibility=&quot;gone&quot;/&gt;
  
              &lt;LinearLayout
                  android:id=&quot;@+id/mechNoData&quot;
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:orientation=&quot;vertical&quot;&gt;
  
                  &lt;include layout=&quot;@layout/no_data_found&quot;/&gt;
  
              &lt;/LinearLayout&gt;
  
  
              &lt;TextView
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_marginTop=&quot;16dp&quot;
                  android:gravity=&quot;center&quot;
                  android:text=&quot;Physics Department&quot;
                  android:textColor=&quot;@color/textColor&quot;
                  android:textSize=&quot;22sp&quot;
                  android:textStyle=&quot;bold&quot;/&gt;
  
              &lt;View
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;1dp&quot;
                  android:layout_marginVertical=&quot;8dp&quot;
                  android:background=&quot;#c1c1c1&quot;/&gt;
  
              &lt;androidx.recyclerview.widget.RecyclerView
                  android:id=&quot;@+id/physicsDepatment&quot;
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:nestedScrollingEnabled=&quot;false&quot;
                  android:visibility=&quot;gone&quot;/&gt;
  
              &lt;LinearLayout
                  android:id=&quot;@+id/physicsNoData&quot;
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:orientation=&quot;vertical&quot;&gt;
  
                  &lt;include layout=&quot;@layout/no_data_found&quot;/&gt;
  
              &lt;/LinearLayout&gt;
  
  
              &lt;TextView
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:layout_marginTop=&quot;16dp&quot;
                  android:gravity=&quot;center&quot;
                  android:text=&quot;Chemistry Department&quot;
                  android:textColor=&quot;@color/textColor&quot;
                  android:textSize=&quot;22sp&quot;
                  android:textStyle=&quot;bold&quot;/&gt;
  
              &lt;View
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;1dp&quot;
                  android:layout_marginVertical=&quot;8dp&quot;
                  android:background=&quot;#c1c1c1&quot;/&gt;
  
              &lt;androidx.recyclerview.widget.RecyclerView
                  android:id=&quot;@+id/chemistryDepatment&quot;
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:nestedScrollingEnabled=&quot;false&quot;
                  android:visibility=&quot;gone&quot;/&gt;
  
              &lt;LinearLayout
                  android:id=&quot;@+id/chemistryNoData&quot;
                  android:layout_width=&quot;match_parent&quot;
                  android:layout_height=&quot;wrap_content&quot;
                  android:orientation=&quot;vertical&quot;&gt;
  
                  &lt;include layout=&quot;@layout/no_data_found&quot;/&gt;
  
              &lt;/LinearLayout&gt;
  
  
          &lt;/LinearLayout&gt;
  
      &lt;/androidx.core.widget.NestedScrollView&gt;
  
  &lt;/androidx.coordinatorlayout.widget.CoordinatorLayout&gt;
  </code></pre>
  <p>**UpdateFaculty.java:
  **</p>
  <pre><code>package com.example.adminuniversityapp.facculty;
  
  import androidx.annotation.NonNull;
  import androidx.appcompat.app.AppCompatActivity;
  import androidx.recyclerview.widget.LinearLayoutManager;
  import androidx.recyclerview.widget.RecyclerView;
  
  import android.content.Intent;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.LinearLayout;
  import android.widget.Toast;
  
  import com.example.adminuniversityapp.R; // i had to import this from the other package in order for  R.layout works
  import com.google.android.material.floatingactionbutton.FloatingActionButton;
  import com.google.firebase.database.DataSnapshot;
  import com.google.firebase.database.DatabaseError;
  import com.google.firebase.database.DatabaseReference;
  import com.google.firebase.database.FirebaseDatabase;
  import com.google.firebase.database.ValueEventListener;
  
  import java.util.ArrayList;
  import java.util.List;
  
  public class UpdateFaculty extends AppCompatActivity {
  
      FloatingActionButton fab;
      private RecyclerView csDepartment, mechanicalDepartment, physicalDepartment, chemistryDepartment;
      private LinearLayout csNoData, mechNoData, physicsNoData, chemistryNoData;
      private List&lt;TeacherData&gt; list, list2, list3, list4;
      private TeacherAdapter adapter;
  
      private DatabaseReference reference, dbRef;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_update_faculty);
  
          csDepartment = findViewById(R.id.csDepartment);
          mechanicalDepartment = findViewById(R.id.mechanicalDepartment);
          physicalDepartment = findViewById(R.id.physicsDepatment);
          chemistryDepartment = findViewById(R.id.chemistryDepatment);
  
          csNoData = findViewById(R.id.csDepartment);
          mechNoData = findViewById(R.id.mechNoData);
          physicsNoData = findViewById(R.id.physicsNoData);
          chemistryNoData = findViewById(R.id.chemistryNoData);
  
          reference = FirebaseDatabase.getInstance().getReference().child(&quot;teacher&quot;);
  
  
          csDepartment();
          mechanicalDepartment();
          physicalDepartment();
          chemistryDepartment();
  
          fab = findViewById(R.id.fab);
  
          fab.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  startActivity(new Intent(UpdateFaculty.this, addTeacher.class));
              }
          });
      }
  
      private void csDepartment() {
          dbRef = reference.child(&quot;Computer Science&quot;);
          dbRef.addValueEventListener(new ValueEventListener() {
              @Override
              public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                  list = new ArrayList&lt;&gt;();
                  if(!dataSnapshot.exists()){
                      csNoData.setVisibility(View.VISIBLE);
                      csDepartment.setVisibility(View.GONE);
                  } else {
                      csNoData.setVisibility(View.GONE);
                      csDepartment.setVisibility(View.VISIBLE);
                      for (DataSnapshot snapshot: dataSnapshot.getChildren()){
                          TeacherData data = snapshot.getValue(TeacherData.class);
                          list.add(data);
                      }
                      csDepartment.setHasFixedSize(true);
                      csDepartment.setLayoutManager(new LinearLayoutManager(UpdateFaculty.this));
                      adapter = new TeacherAdapter(list, UpdateFaculty.this);
                      csDepartment.setAdapter(adapter);
  
                  }
  
              }
  
              @Override
              public void onCancelled(@NonNull DatabaseError databaseError) {
  
                  Toast.makeText(UpdateFaculty.this, databaseError.getMessage(), Toast.LENGTH_SHORT).show();
  
              }
          });
      }
  
      private void mechanicalDepartment() {
          dbRef = reference.child(&quot;Mechanical&quot;);
          dbRef.addValueEventListener(new ValueEventListener() {
              @Override
              public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                  list2 = new ArrayList&lt;&gt;();
                  if(!dataSnapshot.exists()){
                      mechNoData.setVisibility(View.VISIBLE);
                      mechanicalDepartment.setVisibility(View.GONE);
                  } else {
                      mechNoData.setVisibility(View.GONE);
                      mechanicalDepartment.setVisibility(View.VISIBLE);
                      for (DataSnapshot snapshot: dataSnapshot.getChildren()){
                          TeacherData data = snapshot.getValue(TeacherData.class);
                          list2.add(data);
                      }
                      mechanicalDepartment.setHasFixedSize(true);
                      mechanicalDepartment.setLayoutManager(new LinearLayoutManager(UpdateFaculty.this));
                      adapter = new TeacherAdapter(list2, UpdateFaculty.this);
                      mechanicalDepartment.setAdapter(adapter);
  
                  }
  
              }
  
              @Override
              public void onCancelled(@NonNull DatabaseError databaseError) {
  
                  Toast.makeText(UpdateFaculty.this, databaseError.getMessage(), Toast.LENGTH_SHORT).show();
  
              }
          });
      }
  
      private void physicalDepartment() {
          dbRef = reference.child(&quot;Physics&quot;);
          dbRef.addValueEventListener(new ValueEventListener() {
              @Override
              public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                  list3 = new ArrayList&lt;&gt;();
                  if(!dataSnapshot.exists()){
                      physicsNoData.setVisibility(View.VISIBLE);
                      physicalDepartment.setVisibility(View.GONE);
                  } else {
                      physicsNoData.setVisibility(View.GONE);
                      physicalDepartment.setVisibility(View.VISIBLE);
                      for (DataSnapshot snapshot: dataSnapshot.getChildren()){
                          TeacherData data = snapshot.getValue(TeacherData.class);
                          list3.add(data);
                      }
                      physicalDepartment.setHasFixedSize(true);
                      physicalDepartment.setLayoutManager(new LinearLayoutManager(UpdateFaculty.this));
                      adapter = new TeacherAdapter(list3, UpdateFaculty.this);
                      physicalDepartment.setAdapter(adapter);
  
                  }
  
              }
  
              @Override
              public void onCancelled(@NonNull DatabaseError databaseError) {
  
                  Toast.makeText(UpdateFaculty.this, databaseError.getMessage(), Toast.LENGTH_SHORT).show();
  
              }
          });
      }
  
      private void chemistryDepartment() {
          dbRef = reference.child(&quot;Chemistry&quot;);
          dbRef.addValueEventListener(new ValueEventListener() {
              @Override
              public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
                  list4 = new ArrayList&lt;&gt;();
                  if(!dataSnapshot.exists()){
                      chemistryNoData.setVisibility(View.VISIBLE);
                      chemistryDepartment.setVisibility(View.GONE);
                  } else {
                      chemistryNoData.setVisibility(View.GONE);
                      chemistryDepartment.setVisibility(View.VISIBLE);
                      for (DataSnapshot snapshot: dataSnapshot.getChildren()){
                          TeacherData data = snapshot.getValue(TeacherData.class);
                          list4.add(data);
                      }
                      chemistryDepartment.setHasFixedSize(true);
                      chemistryDepartment.setLayoutManager(new LinearLayoutManager(UpdateFaculty.this));
                      adapter = new TeacherAdapter(list4, UpdateFaculty.this);
                      chemistryDepartment.setAdapter(adapter);
  
                  }
  
              }
  
              @Override
              public void onCancelled(@NonNull DatabaseError databaseError) {
  
                  Toast.makeText(UpdateFaculty.this, databaseError.getMessage(), Toast.LENGTH_SHORT).show();
  
              }
          });
      }
  }
  </code></pre>
  <p>Here is what it shows on the <strong>logcat</strong> right after I click the <strong>Update Faculty</strong> MaterialCardView :</p>
  <pre><code>2022-03-22 14:09:03.319 24645-24645/com.example.adminuniversityapp I/Timeline: Timeline: Activity_launch_request time:36107995
  2022-03-22 14:09:03.344 24645-24702/com.example.adminuniversityapp V/FA: Recording user engagement, ms: 49869
  2022-03-22 14:09:03.367 24645-24702/com.example.adminuniversityapp V/FA: Connecting to remote service
  2022-03-22 14:09:03.369 24645-24671/com.example.adminuniversityapp V/FA: onActivityCreated
  2022-03-22 14:09:03.373 24645-24702/com.example.adminuniversityapp V/FA: Connection attempt already in progress
  2022-03-22 14:09:03.373 24645-24702/com.example.adminuniversityapp V/FA: Activity paused, time: 61111997
  2022-03-22 14:09:03.375 24645-24645/com.example.adminuniversityapp D/DecorView[]: getWindowModeFromSystem  windowmode is 1
  2022-03-22 14:09:03.409 24645-24645/com.example.adminuniversityapp E/libc: Access denied finding property &quot;ro.vendor.pref_scale_resolution&quot;
  2022-03-22 14:09:03.409 24645-24645/com.example.adminuniversityapp I/FloatingActionButton: Setting a custom background is not supported.
  2022-03-22 14:09:03.411 24645-24645/com.example.adminuniversityapp E/libc: Access denied finding property &quot;ro.vendor.pref_scale_resolution&quot;
  2022-03-22 14:09:03.468 24645-24645/com.example.adminuniversityapp E/libc: Access denied finding property &quot;ro.vendor.pref_scale_resolution&quot;
  2022-03-22 14:09:03.509 24645-24645/com.example.adminuniversityapp D/AndroidRuntime: Shutting down VM
  2022-03-22 14:09:03.513 24645-24645/com.example.adminuniversityapp E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.example.adminuniversityapp, PID: 24645
      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.adminuniversityapp/com.example.adminuniversityapp.facculty.UpdateFaculty}: java.lang.ClassCastException: androidx.recyclerview.widget.RecyclerView cannot be cast to android.widget.LinearLayout
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3580)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3752)
          at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
          at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
          at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2191)
          at android.os.Handler.dispatchMessage(Handler.java:106)
          at android.os.Looper.loop(Looper.java:236)
          at android.app.ActivityThread.main(ActivityThread.java:8049)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:620)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1011)
       Caused by: java.lang.ClassCastException: androidx.recyclerview.widget.RecyclerView cannot be cast to android.widget.LinearLayout
          at com.example.adminuniversityapp.facculty.UpdateFaculty.onCreate(UpdateFaculty.java:46)
        
      
  </code></pre>