0

I recently started learning to dev android code. I had this simple program working fine until i tried integrate v7-appcompat to allow use of the action bar. Now my program instantly crashes on launch. Any ideas?

Logcat:

02-27 21:15:14.958: D/AndroidRuntime(680): Shutting down VM
02-27 21:15:14.958: W/dalvikvm(680): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
02-27 21:15:14.969: E/AndroidRuntime(680): FATAL EXCEPTION: main
02-27 21:15:14.969: E/AndroidRuntime(680): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mikemiles/com.mikemiles.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
02-27 21:15:14.969: E/AndroidRuntime(680):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
02-27 21:15:14.969: E/AndroidRuntime(680):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-27 21:15:14.969: E/AndroidRuntime(680):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-27 21:15:14.969: E/AndroidRuntime(680):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-27 21:15:14.969: E/AndroidRuntime(680):  at android.os.Handler.dispatchMessage(Handler.java:99)
02-27 21:15:14.969: E/AndroidRuntime(680):  at android.os.Looper.loop(Looper.java:123)
02-27 21:15:14.969: E/AndroidRuntime(680):  at android.app.ActivityThread.main(ActivityThread.java:4627)
02-27 21:15:14.969: E/AndroidRuntime(680):  at java.lang.reflect.Method.invokeNative(Native Method)
02-27 21:15:14.969: E/AndroidRuntime(680):  at java.lang.reflect.Method.invoke(Method.java:521)
02-27 21:15:14.969: E/AndroidRuntime(680):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-27 21:15:14.969: E/AndroidRuntime(680):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-27 21:15:14.969: E/AndroidRuntime(680):  at dalvik.system.NativeStart.main(Native Method)
02-27 21:15:14.969: E/AndroidRuntime(680): Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
02-27 21:15:14.969: E/AndroidRuntime(680):  at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:111)
02-27 21:15:14.969: E/AndroidRuntime(680):  at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
02-27 21:15:14.969: E/AndroidRuntime(680):  at com.mikemiles.MainActivity.onCreate(MainActivity.java:15)
02-27 21:15:14.969: E/AndroidRuntime(680):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-27 21:15:14.969: E/AndroidRuntime(680):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
02-27 21:15:14.969: E/AndroidRuntime(680):  ... 11 more

Thanks in advance!

EDIT:

mrres1: I wrote it myself but followed the tutorial here: https://developer.android.com/training/basics/actionbar/setting-up.html

my layout file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <EditText android:id="@+id/edit_message"
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:hint="@string/edit_message" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/button_send"
        android:onClick="sendMessage" />

</LinearLayout>

manifest file:

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

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.mikemiles.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.mikemiles.DisplayMessageActivity"
            android:label="@string/title_activity_display_message"
            android:parentActivityName="com.mikemiles.myfirstapp.MainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.mikemiles.myfirstapp.MainActivity" />
        </activity>
    </application>

</manifest>
mmiles19
  • 21
  • 1
  • 7
  • The problem is probably in your xml layout file, can you post your style.xml file? – GhostDerfel Feb 28 '14 at 03:23
  • @Mike Is this a project you've started, or an imported project? – mrres1 Feb 28 '14 at 03:24
  • Share your android manifest file. – Peshal Feb 28 '14 at 03:26
  • @Mike since you are trying to use `Actionbar` for Android lower than 3.0 and need `v7-appcompat` which you are using but in addition to that in `manifest` you need to replace existing them with `android:theme="@style/Theme.AppCompat" in the application tag. – Atif Farrukh Feb 28 '14 at 04:34
  • Hey guys! Thank you all for your help. I thought I had changed that in the manifest file but maybe i forgot to save or something - anyways, its working now. Great to have an amazing community like this. Thanks again. – mmiles19 Feb 28 '14 at 06:27

1 Answers1

0

add android:theme="@style/Theme.AppCompat" in your MainActivity in manifest

<activity
    android:name="com.mikemiles.MainActivity"
     android:theme="@style/Theme.AppCompat"
    android:label="@string/app_name" >
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>
Yahya Arshad
  • 1,626
  • 2
  • 19
  • 34