본문 바로가기
Android

getActionBar가 null pointer exception이 나올 때

by 루에 2015. 4. 16.
반응형

몇 가지 차례대로 확인한다.



First, if getActionBar() in an Activity is returning null, then you do not have a native action bar in your activity.

Second, android.support.v7.app.ActionBarDrawerToggle does not work with the native action bar. It works with the appcompat-v7 action bar backport. If you are going to use android.support.v7.app.ActionBarDrawerToggle, then you have to move your app over to use appcompat-v7:

  1. Add appcompat-v7 as a dependency

  2. Inherit from ActionBarActivity instead of Activity

  3. Call getSupportActionBar() rather than getActionBar()

  4. Use Theme.AppCompat (or something that inherits from it) as your activity's theme


요컨대 이슈는 기본 액션바를 썼느냐 커스텀 했느냐에 따라 getActionBar()가 아닐 가능성이 있다는 것. 본인은 3번으로 해결을 했고, 대부분 이 정도에서 해결가능할 것이다.

반응형

댓글