启动时出现Android错误

时间:2015-07-06 23:48:46

标签: java android gradle startup logcat

我正在尝试在我的Android设备上运行我的应用程序但不幸的是我不能。我的logcat:

> Process: com.android.app.myapplication, PID: 15138
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.android.app.myapplication/com.android.app.myapplication.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.    
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2198)           
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)         
at android.app.ActivityThread.access$800(ActivityThread.java:139)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132)
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.AppCompatDelegateImplBase.onCreate(AppCompatDelegateImplBase.java:122)
> at
> android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:146)
> at
> android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:59)
> at
> com.android.app.myapplication.MainActivity.onCreate(MainActivity.java:13)
> at android.app.Activity.performCreate(Activity.java:5248) at
> android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
> at
> android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
> at
> android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
> at android.app.ActivityThread.access$800(ActivityThread.java:139) at
> android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
> at android.os.Handler.dispatchMessage(Handler.java:102) at
> android.os.Looper.loop(Looper.java:136) at
> android.app.ActivityThread.main(ActivityThread.java:5086) 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:785)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) at
> de.robv.android.xposed.XposedBridge.main(XposedBridge.java:132) at
> dalvik.system.NativeStart.main(Native Method)

我认为它与清单,API,Gradle脚本或其他东西有关,因为我的活动和布局没有错误。

3 个答案:

答案 0 :(得分:1)

结帐You need to use a Theme.AppCompat theme (or descendant) with this activity。可能你的活动正在扩展不正确的超类。

答案 1 :(得分:0)

转到文件清单并更改主题。

<application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:largeHeap="true"
        android:theme="@style/Tema" > <------ Change here (You can put Theme.AppCompat or others from that

答案 2 :(得分:0)

确保您的活动扩展了appacompact活动

public class BaseActivity extends AppCompatActivity {

...
}

并且您的style.xml需要一个Theme.AppCompact

版本
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">

  </style>

最后确保清单中的应用程序类指向该样式

 <application
    android:theme="@style/AppTheme">