0

I went through a code where setSupportActionBar(toolbar) method was used without object of AppCompatActivity class. But when I went on implementing some code, I found it rejecting the way. It is important to use it as the toolbar I am passing as parameter to the above mentioned function is of type androidx.appcompat.widget.toolbar.

After implementing it, there is no compile time error, but facing error when starting the emulator:

"Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void androidx.appcompat.app.AppCompatActivity.setSupportActionBar(androidx.appcompat.widget.Toolbar)' on a null object reference'.

James Z
  • 12,209
  • 10
  • 24
  • 44
Abir
  • 1
  • 1

0 Answers0