android studio我的helloWorld项目已停止

时间:2014-08-01 10:08:18

标签: android logcat avd

我刚刚灌输了Android Studio,当我在模拟器中运行示例项目hello world时,它让我的项目已停止并且无法正常工作

myActivity.java

    package b3du.im.myapplication;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;


public class MyActivity extends ActionBarActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);

    }
}

activity_my.xml

<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".MyActivity">

    <TextView
        android:text="@string/hello_world"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>

的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="b3du.im.myapplication" >

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MyActivity"
            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>

logcat错误

08-01 05:13:56.557    1884-1884/b3du.im.myapplication I/Process﹕ Sending signal. PID: 1884 SIG: 9
08-01 05:21:26.244    1944-1944/b3du.im.myapplication D/AndroidRuntime﹕ Shutting down VM
08-01 05:21:26.244    1944-1944/b3du.im.myapplication W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb2cc9b20)
08-01 05:21:26.284    1944-1944/b3du.im.myapplication E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: b3du.im.myapplication, PID: 1944
    java.lang.RuntimeException: Unable to start activity ComponentInfo{b3du.im.myapplication/b3du.im.myapplication.MyActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
            at android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:108)
            at android.support.v7.app.ActionBarActivityDelegateICS.onCreate(ActionBarActivityDelegateICS.java:57)
            at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:98)
            at b3du.im.myapplication.MyActivity.onCreate(MyActivity.java:11)
            at android.app.Activity.performCreate(Activity.java:5231)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5017)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
            at dalvik.system.NativeStart.main(Native Method)

3 个答案:

答案 0 :(得分:1)

这是因为您使用ActionBarActivity,这需要应用AppCompat主题。

使用该主题,或使用简单的Activity。见a similar issue

答案 1 :(得分:0)

由MysticMagic声明将ActionBarActivity更改为Activity或将您的主题更改为AppCompat 探索包得到res-&gt; values-&gt; style.xml和更改样式

<style name="AppBaseTheme" parent="Theme.AppCompat.Light">

答案 2 :(得分:0)

您的问题与您当前在应用中设置的AppTheme有关。

引起:java.lang.IllegalStateException:您需要对此活动使用Theme.AppCompat主题(或后代)。             在android.support.v7.app.ActionBarActivityDelegate.onCreate(ActionBarActivityDelegate.java:108)

您正在从ActionBarActivity继承您,因此您必须为您的应用程序使用Theme.AppCompat。将styles.xml中的app基础主题更改为

<style name="AppBaseTheme" parent="@style/Theme.AppCompat.Light">

如果您在加载此主题时遇到问题,请按照以下链接解决编译问题。

Can't Find Theme.AppCompat.Light for New Android ActionBar Support