2014-11-03 3 views
0

Так что я пытаюсь использовать Android Studio для проекта класса, но даже делает пустую операцию, которая должна отображать «HelloWorld», когда я пытаюсь запустить ее, и я не знаю почему. Я не знаю, как заставить консоль ошибок отображаться, поэтому я подумал, что попробую опубликовать код здесь и посмотреть, есть ли что-то не так с ним по какой-то причине.Вспышка приложения Hello World android при запуске

Manifest:

<?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); 
    } 
} 

Это именно то, что андроид студия сделал, когда я сделал новый проект с пустой деятельностью.

Редактировать: получил стек, вот он.

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) 
+0

Вы смотрели на журналы? – Populus

+0

Вам не хватает самой важной информации: Какова ваша трассировка ошибок (Stacktrace). –

+0

Соответствует ли ваша версия версии целевой платформы? –

ответ

0

В журналах вы можете увидеть эту строку:

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

Проверить этот разговор: You need to use a Theme.AppCompat theme (or descendant) with this activity

+0

Спасибо, заметили что-то об уровнях api, поэтому я попробовал более высокий, и он работал сразу с места в карьер. – Majeh

Смежные вопросы