Script Kitty Script Kitty - 1 year ago 93
Android Question

Android Crash on start: Styling the ActionBar Theme App.Compat

I don't want to post since it seems simple. For the sake of simplicity I'll provide as much detail as I can without throwing up a bunch of logcat and expecting a cure all.

Following the google tutorial for styling an action bar. Win7, Android Studio, Android 5, API 19 KitKat (Min SDK Version 11) no support library, Gradle 1.8 I think. excerpt:

public class MainActivity extends ActionBarActivity {

protected void onCreate(Bundle savedInstanceState) {
//ERRORS: // super.onCreate(savedInstanceState);
//ERRORS: // setContentView(R.layout.activity_main);

public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getMenuInflater();
inflater.inflate(, menu);
return super.onCreateOptionsMenu(menu);

public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
switch (item.getItemId()) {
// openSearch();
return true;
// openSettings();
return true;
return super.onOptionsItemSelected(item);

LogCat excerpt(when SuperNotCalled):

Process: gaga.june, PID: 8726
android.util.SuperNotCalledException: Activity {gaga.june/gaga.june.MainActivity} did not call through to super.onCreate()

LogCat excerpt (when I put in the Super):

Unable to start activity ComponentInfo{gaga.june/gaga.june.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.

AndroidManifest.xml excerpt:

<uses-sdk android:minSdkVersion="11"/>

android:parentActivityName="gaga.june.MainActivity" >
<!-- Parent activity meta-data to support 4.0 and lower -->
android:value="gaga.june.MainActivity" />

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


  • Normally in the onCreate I would put
    However, when I debug that line is the one that throws the error so some other people on SO commented it out to not inherit the previous overriden onCreate. I did the same

  • setContentView(R.layout.activity_main);
    Also gives me an error when debugging. Checked the manual, they said that you must define the ListView if it gives you an error like that. But I'm not using a listview, I only defined
    Therefore, I commented it out

  • I changed my style from
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <style name="AppTheme" parent="Theme.AppCompat.Light">

  • Other than that I pretty much followed the tutorial exactly to my project. If I could just identify what all these problems mean that would be great (SO is always a last resort I may just skip this tutorial). Thanks so much

    EDIT CustomActionBarTheme from themes.xml:

    <!-- Theme applied to app/activity -->
    <style name="CustomActionBarTheme"
    <item name="android:actionBarStyle">@style/MyActionBar</item>
    <item name="actionBarStyle">@style/MyActionBar</item>

    Answer Source

    First of all in your onCreate method:

    • you have to call the super method
    • you have to define your layout with setContentView method
    • you have to use the getSupportActionBar() instead of getActionBar method

    Something like:

        protected void onCreate(Bundle savedInstanceState) {

    Then you have to change the style CustomActionBarTheme used by your MainActivity, because the ActionBarActivity requires an AppCompat theme

    <!-- Theme applied to app/activity -->
    <style name="CustomActionBarTheme"

    Finally I suggest you switching to the new app-compat v 22.2.0 changing your build.gradle

    dependencies {
         compile ''

    With this version the ActionBarActivity is deprecated. You can use now the AppCompatActivity