แอพ Android Hello World ขัดข้องเมื่อเริ่มต้น [ซ้ำกัน]

ดังนั้นฉันจึงพยายามใช้ Android Studio สำหรับโปรเจ็กต์ของชั้นเรียน แต่ทำกิจกรรมว่างๆ ที่ควรแสดง "HelloWorld" ขัดข้องเมื่อฉันลองเริ่มมัน และฉันไม่รู้ว่าทำไม ฉันไม่รู้ว่าจะแสดงคอนโซลข้อผิดพลาดได้อย่างไร ดังนั้นฉันจึงคิดว่าจะลองโพสต์โค้ดที่นี่และดูว่ามีอะไรผิดปกติด้วยเหตุผลบางประการหรือไม่

ประจักษ์:

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

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

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=".TestApp">

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

</RelativeLayout>

กิจกรรม

package com.example.majeh.myapp;

import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


public class TestApp extends ActionBarActivity {

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


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.test_app, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}

นี่เป็นเพียงสิ่งที่ android studio สร้างขึ้นเมื่อฉันสร้างโปรเจ็กต์ใหม่โดยมีกิจกรรมว่างเปล่า

แก้ไข: ได้รับ stacktrace แล้ว นี่ไง

11-03 13:39:30.470    2273-2273/com.example.majeh.myapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.example.majeh.myapp, PID: 2273
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.majeh.myapp/com.example.majeh.myapp.TestApp}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
     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:147)
            at android.support.v7.app.ActionBarActivityDelegateBase.onCreate(ActionBarActivityDelegateBase.java:139)
            at android.support.v7.app.ActionBarActivity.onCreate(ActionBarActivity.java:123)
            at com.example.majeh.myapp.TestApp.onCreate(TestApp.java:13)
            at android.app.Activity.performCreate(Activity.java:5933)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

person Majeh    schedule 03.11.2014    source แหล่งที่มา
comment
คุณได้ดูบันทึกแล้วหรือยัง?   -  person Populus    schedule 03.11.2014
comment
คุณขาดข้อมูลที่สำคัญที่สุด: อะไรคือการติดตามข้อผิดพลาดของคุณ (Stacktrace)   -  person Rolf ツ    schedule 03.11.2014
comment
งานสร้างของคุณตรงกับเวอร์ชันของแพลตฟอร์มเป้าหมายหรือไม่   -  person Paul Sasik    schedule 03.11.2014
comment
ที่มุมล่างซ้ายของหน้าต่าง Android-Studio: มีไอคอนเล็ก ๆ : วางเมาส์ไว้แล้วเลือก Android ในเมนูป๊อปอัป: คุณจะเห็นคอนโซล (เรียกอีกอย่างว่า logcat บน Android)   -  person ben75    schedule 03.11.2014


คำตอบ (1)


ในบันทึกคุณสามารถดูบรรทัดนี้:

You need to use a Theme.AppCompat theme (or descendant) with this activity.

ตรวจสอบการสนทนานี้: คุณต้องการ เพื่อใช้ธีม Theme.AppCompat (หรือสืบทอด) กับกิจกรรมนี้

person Vincent D.    schedule 03.11.2014
comment
ขอบคุณ สังเกตเห็นบางอย่างเกี่ยวกับระดับ API เช่นกัน ดังนั้นฉันจึงลองใช้ระดับที่สูงกว่าและมันก็ได้ผลทันที - person Majeh; 03.11.2014