-3

I am getting the following error when I open my app as a result of which the apl crashes right on start

Attempt to invoke virtual method 'void androidx.recyclerview.widget.RecyclerView.setAdapter(androidx.recyclerview.widget.RecyclerView$Adapter)' on a null object reference
        at com.akash.writer.MainActivity.onCreate(MainActivity.java:43)
gtxtreme
  • 1,830
  • 1
  • 13
  • 25

1 Answers1

0

Based on your error message it's seems like you're trying to set adapter to recycelrView without initializing it. Please initialize the recyclerView before setting adapter to it.

As you're using JAVA here is a rough example how you could initialize your recyclerView

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState)
    setContentView(R.id.your_layout)

    //Initialize your recycler view first
    RecyclerView yourRecyclerView = findViewById(R.id.your_recycler_view_id)

    //now set your adapter to your recycler view
    yourRecyclerView.setAdapter(yourAdapter)
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
Ngima Sherpa
  • 1,397
  • 1
  • 13
  • 34