I am trying to inflate my recyclerview activity with an adapter

no error appears while building or in logcat but when app runs nothing is being displayed.

Here is my activity xml:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".ui.courses.EngActivity"
>


<androidx.recyclerview.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/recyclerview"
    >

</androidx.recyclerview.widget.RecyclerView>


</LinearLayout>

My layout to be inflated

<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="3dp"
app:cardElevation="3dp"
app:cardUseCompatPadding="true">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="16dp">

    <ImageView
        android:id="@+id/college_icon"
        android:layout_width="165dp"
        android:layout_height="125dp"
        android:scaleType="centerCrop"
        android:src="@drawable/iitb" />

    <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="11dp"
        android:layout_marginStart="11dp"
        android:layout_toRightOf="@+id/college_icon"
        android:layout_toEndOf="@+id/college_icon"
        android:text="Indian Institute of Technology Bombay-IITB"
        android:textColor="#000"
        android:textSize="16sp"
        android:textStyle="bold" />



</RelativeLayout>

</androidx.cardview.widget.CardView>

Main class:

public class EngActivity extends AppCompatActivity {

RecyclerView recyclerView;
MyAdapter adapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_eng);

    recyclerView=findViewById(R.id.recyclerview);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    adapter= new MyAdapter(this,getMyList());
    recyclerView.setAdapter(adapter);
}

private ArrayList<Model> getMyList(){
    ArrayList<Model> models= new ArrayList<>();
    Model m;
    m = new Model();
    m.setTitle("Indian Institute of Technology Bombay-IITB");
    m.setDescription("Mumbai, Maharashtra");
    m.setCourse("BE/B.Tech - Bachelor of Technology");
    m.setFees("₹211,400 per year");
    m.setImg(R.drawable.iitb);

    m=new Model();
    m.setTitle("Indian Institute of Technology Delhi-IITD");
    m.setDescription("New Delhi, Delhi NCR");
    m.setCourse("BE/B.Tech - Bachelor of Technology");
    m.setFees("₹224,900 per year");
    m.setImg(R.drawable.iitd);

    m=new Model();
    m.setTitle("Birla Institute of Technology and Science-BITS");
    m.setDescription("Pilani, Rajasthan");
    m.setCourse("BE/B.Tech - Bachelor of Technology");
    m.setFees("₹423,475 per year");
    m.setImg(R.drawable.bits);

    m=new Model();
    m.setTitle("Bennett University");
    m.setDescription("Greater Noida, Uttar Pradesh");
    m.setCourse("BE/B.Tech - Bachelor of Technology");
    m.setFees("₹425,000 per year");
    m.setImg(R.drawable.bu);



    return models;
}
}

Adapter class to add items in the recycler view:

public class MyAdapter extends RecyclerView.Adapter<MyHolder> {

Context c;
ArrayList<Model> models;

public MyAdapter(Context c, ArrayList<Model> models) {
    this.c = c;
    this.models = models;
}

@NonNull
@Override
public MyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

    View view= LayoutInflater.from(parent.getContext()).inflate(R.layout.row,null);
    return new MyHolder(view);
}

@Override
public void onBindViewHolder(@NonNull MyHolder holder, int position) {

    holder.mTitle.setText(models.get(position).getTitle());
    holder.mDes.setText(models.get(position).getDescription());
    holder.mCourse.setText(models.get(position).getCourse());
    holder.mFee.setText(models.get(position).getFees());
    holder.mImageView.setImageResource(models.get(position).getImg());
}

@Override
public int getItemCount() {
    return models.size();
}
}

After i inflate in Engactivity java class it is just displaying empty activity in the build How can i solve this?

Answer

You forgot to include ArrayList add method.

add(Object o) : This method appends the specified element to the end of this list.

ArrayList<Model> models= new ArrayList<>();
    Model m;
    m = new Model();
    m.setTitle("Indian Institute of Technology Bombay-IITB");
    m.setDescription("Mumbai, Maharashtra");
    m.setCourse("BE/B.Tech - Bachelor of Technology");
    m.setFees("₹211,400 per year");
    m.setImg(R.drawable.iitb);

     models.add(new Model(m));

   m=new Model();
   m.setTitle("Indian Institute of Technology Delhi-IITD");
   m.setDescription("New Delhi, Delhi NCR");
   m.setCourse("BE/B.Tech - Bachelor of Technology");
   m.setFees("₹224,900 per year");
   m.setImg(R.drawable.iitd);

    models.add(new Model(m));