Question

I've got a little app where I have a title bar present. I want to get rid of it and read that I should change the theme in the manifest to @android:style/Theme.NoTitleBar.Fullscreen. (It was @style/AppTheme

I had to browse the noTitle theme from the system resources and added it.

Now, if I boot up the app it says it 'unfortunately stopped working'.

My manifest:

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

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
        <activity
            android:name="com.example.esrmdesign.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>
    </application>

</manifest>

activity_main.xml:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.example.esrmdesign.MainActivity"
    tools:ignore="MergeRootFrame" />

logcat:

05-15 05:15:03.670: E/AndroidRuntime(908): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.esrmdesign/com.example.esrmdesign.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
05-15 05:15:03.670: E/AndroidRuntime(908):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
05-15 05:15:03.670: E/AndroidRuntime(908):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
05-15 05:15:03.670: E/AndroidRuntime(908):  at android.app.ActivityThread.access$800(ActivityThread.java:135)
05-15 05:15:03.670: E/AndroidRuntime(908):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
05-15 05:15:03.670: E/AndroidRuntime(908):  at android.os.Handler.dispatchMessage(Handler.java:102)
05-15 05:15:03.670: E/AndroidRuntime(908):  at android.os.Looper.loop(Looper.java:136)
05-15 05:15:03.670: E/AndroidRuntime(908):  at android.app.ActivityThread.main(ActivityThread.java:5017)
05-15 05:15:03.670: E/AndroidRuntime(908):  at java.lang.reflect.Method.invokeNative(Native Method)
05-15 05:15:03.670: E/AndroidRuntime(908):  at java.lang.reflect.Method.invoke(Method.java:515)
05-15 05:15:03.670: E/AndroidRuntime(908):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-15 05:15:03.670: E/AndroidRuntime(908):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-15 05:15:03.670: E/AndroidRuntime(908):  at dalvik.system.NativeStart.main(Native Method)
05-15 05:15:03.670: E/AndroidRuntime(908): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
05-15 05:15:03.670: E/AndroidRuntime(908):  at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:111)
05-15 05:15:03.670: E/AndroidRuntime(908):  at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:58)
05-15 05:15:03.670: E/AndroidRuntime(908):  at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
05-15 05:15:03.670: E/AndroidRuntime(908):  at com.example.esrmdesign.MainActivity.onCreate(MainActivity.java:18)
05-15 05:15:03.670: E/AndroidRuntime(908):  at android.app.Activity.performCreate(Activity.java:5231)
05-15 05:15:03.670: E/AndroidRuntime(908):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
05-15 05:15:03.670: E/AndroidRuntime(908):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
05-15 05:15:03.670: E/AndroidRuntime(908):  ... 11 more
Was it helpful?

Solution

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

This exception is thrown when you are using appcompat library for ActionBar and not setting a compatible theme in your manifest file. The compatible themes can be for e.g

android:theme="@style/Theme.AppCompat.Light"

If you are using appcompat library to support ActionBar from API 7 or more, you need to keep track of the following info,

1.Always use the latest appcompat library.

2.Don't forget to add compatible theme like below as per your need. e.g:

android:theme="@style/Theme.AppCompat.Light"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar"

3.Don't use requestWindowFeature(Window.FEATURE_NO_TITLE); in the Java file i.e don't hide the TitleBar. Because ActionBar is the replacement of it.

OTHER TIPS

It seems you are trying to use an ActionBar in your Activity which is the reason you are getting the IllegalStateException.

Change the theme to android:theme="@style/ThemeAppCompat.Light" as suggested in the Exception stacktrace

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top