1

I just instilled Android Studio and when I run the sample project hello world in the emulator it gives me my project has stopped and it doesn't work

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 error

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 Answers3

1

This is because you are using ActionBarActivity, which requires the AppCompat theme to be applied.

Either use that theme, Or use simple Activity. See a similar issue

Community
  • 1
  • 1
MysticMagicϡ
  • 28,593
  • 16
  • 73
  • 124
  • 1
    thank you my project works now . I would like to know what is the point using ActionBarActivity instead of Activity –  Aug 01 '14 at 10:16
  • Glad it helped @b3du Please accept answer if the issue is solved. So question gets removed from unanswered question. – MysticMagicϡ Aug 01 '14 at 10:19
  • @b3du [see here](http://developer.android.com/reference/android/support/v7/app/ActionBarActivity.html) for difference. I think it adds it directly in updated SDK. – MysticMagicϡ Aug 01 '14 at 10:23
0

as Stated by MysticMagic change ActionBarActivity to Activity or change your theme to AppCompat explore package got to res-> values->style.xml and change style

<style name="AppBaseTheme" parent="Theme.AppCompat.Light">
jaimin
  • 563
  • 8
  • 25
0

Your issue is with AppTheme that you have set currently in you app.

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)

You are inheriting you from ActionBarActivity so you have to use Theme.AppCompat for your application. Change app base theme in styles.xml to

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

If you are facing issue in loading this theme than please follow the below link to resolve compilation issue.

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

Community
  • 1
  • 1