Android应用程序不断崩溃。帮新手?

时间:2014-02-28 03:21:53

标签: java android crash

我最近开始学习dev android代码。我有这个简单的程序工作正常,直到我尝试集成v7-appcompat允许使用操作栏。现在我的程序在发布时立即崩溃。有什么想法吗?

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

提前致谢!

编辑:

mrres1:我自己写了但是按照这里的教程:https://developer.android.com/training/basics/actionbar/setting-up.html

我的布局文件:

<?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>

清单文件:

<?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>

1 个答案:

答案 0 :(得分:0)

在清单

中的MainActivity中添加android:theme="@style/Theme.AppCompat"
<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>