[Solved] Why do I have to use getSupportActionBar() for activity that extends AppCompatActivity?


  1. AppCompatActivity is activity for older version android up to latest version. so if your targer application is android 2.3 – 6.0 you must extend appcompactactivity rather than just plain activity. and method getActionBar is intended to use with activity. getSupportActionBar is intended to use with appCompactActivity

  2. What you import is a class from other project, not the actual object that has been initialized in your activity. and in your activity you dont initialized the class that you import, and then it becomes NPE ( Null Pointer Exception )

solved Why do I have to use getSupportActionBar() for activity that extends AppCompatActivity?