android – App crash Attempt to invoke virtual method-ThrowExceptions

Exception or error:

After attempt to click on the button to go to the new activity my application crashed with this error

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.recyclerview.widget.RecyclerView.setLayoutManager(androidx.recyclerview.widget.RecyclerView$LayoutManager)' on a null object reference
    at com.example.myapplication.klienci.onCreate(klienci.java:37)

That’s my java class code in “klienci”

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_klienci);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    NoteDatabase db = new NoteDatabase(this);
    notes = db.getNotes();
    recyclerView = findViewById(R.id.listOfNotes);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    adapter = new Adapter(this,notes);
    recyclerView.setAdapter(adapter);

activity_klienci –
https://anotepad.com/notes/brwjw39b

Thanks for help, regards.

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *