1

I am very new to android app development, and have recently hit a wall on the Styling the Action Bar page.

Every time I change the theme to android:theme="@android:style/Theme.Holo.Light" just doesn't allow the program to run on the android, with a message saying "Unfortunately, Program has stopped." every time I try to run it. Weird thing is that it saves perfectly fine on Eclipse with no errors.

Here's my manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.myfirstappv2"
    android:versionCode="1"
    android:versionName="1.0" >

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

    <application

        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Holo"> 

        <activity
            android:name="com.example.myfirstappv2.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.example.myfirstappv2.DisplayMessageActivity"
            android:label="@string/title_activity_display_message"
            android:parentActivityName="com.example.myfirstappv2.MainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.example.myfirstappv2.MainActivity" />
        </activity>
    </application>

</manifest>

LogCat:

06-15 21:17:24.748: E/AndroidRuntime(5350): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myfirstappv2/com.example.myfirstappv2.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
Bonhomme
  • 33
  • 2
  • 10
  • It's crashing with `Theme.Holo.Light` but not with `Theme.Holo`? That's strange. Please post the exception strack trace from logcat. – matiash Jun 16 '14 at 01:12
  • No no it crashes with anything Theme.Holo. It only worked with `android:theme="@style/AppTheme" >`, which was the default. – Bonhomme Jun 16 '14 at 01:15
  • Ah, that's more logical. Please post the exception stack trace. – matiash Jun 16 '14 at 01:16
  • What version of Android are you testing this on? – ianhanniballake Jun 16 '14 at 01:18
  • I'm testing this out on Android Version 4.4.2. How do I post the exception stack trace, if you don't mind me asking – Bonhomme Jun 16 '14 at 01:20
  • See http://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – matiash Jun 16 '14 at 01:30
  • Oh man, you're really helping me out here haha. Here's my runtime Exception: `06-15 21:17:24.748: E/AndroidRuntime(5350): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myfirstappv2/com.example.myfirstappv2.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.` I remember the article saying something about AppCompat, so I'll go check that out in the meantime. – Bonhomme Jun 16 '14 at 01:40

1 Answers1

4

If your Activity is an ActionBarActivity then you need to use one of the Theme.AppCompat variants (i.e. Theme.AppCompat, Theme.AppCompat.Light, &c).

From the Styling the Action Bar page:

Note: If you are using the Support Library APIs for the action bar, then you must use (or override) the Theme.AppCompat family of styles (rather than the Theme.Holo family, available in API level 11 and higher). In doing so, each style property that you declare must be declared twice: once using the platform's style properties (the android: properties) and once using the style properties included in the Support Library (the appcompat.R.attr properties—the context for these properties is actually your app).

Don't forget about the "add the properties twice" part.

matiash
  • 54,791
  • 16
  • 125
  • 154