[Android] NoSuchMethodError with getActionBar()

Tadashi Shigeoka ·  Thu, June 13, 2013

In Android app development, if you want to support devices like 2.3, use ActionBarSherlock’s getSupportActionBar() instead of getActionBar().

Using getActionBar() will cause a NoSuchMethodError.

Thread [<1> main] (Suspended (exception NoSuchMethodError))  
    
  TutorialActivity.onCreate(Bundle) line: 40  
  Instrumentation.callActivityOnCreate(Activity, Bundle) line: 1047  
  ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1615  
  ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1667  
  ActivityThread.access$1500(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 117  
  ActivityThread$H.handleMessage(Message) line: 935  
  ActivityThread$H(Handler).dispatchMessage(Message) line: 99  
  Looper.loop() line: 123  
  ActivityThread.main(String[]) line: 3691  
  Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
  Method.invoke(Object, Object...) line: 507  
  ZygoteInit$MethodAndArgsCaller.run() line: 864  
  ZygoteInit.main(String[]) line: 622  
  NativeStart.main(String[]) line: not available [native method]  

An easy mistake to make.

That’s all from the Gemba.