我是Android新手,一直在线关注Google的基础培训课程。在开始时,minSdkVersion设置为8,但现在我需要将其更改为使用Holo主题http://developer.android.com/training/basics/actionbar/styling.html
问题是,在我将minSdkVersion更新为11或14之后,我的应用程序一直在崩溃....
我更改了build.gradle(Module:app)中的minSdkVersion。
defaultConfig {
applicationId "com.example.cindy.myfirstapp"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
这是logcat错误:
09-29 18:33:49.901 22164-22164/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.cindy.myfirstapp, PID: 22164
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.cindy.myfirstapp/com.example.cindy.myfirstapp.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
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:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplV7.createSubDecor(AppCompatDelegateImplV7.java:309)
at android.support.v7.app.AppCompatDelegateImplV7.ensureSubDecor(AppCompatDelegateImplV7.java:278)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:252)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:109)
at com.example.cindy.myfirstapp.MainActivity.onCreate(MainActivity.java:20)
at android.app.Activity.performCreate(Activity.java:5990)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
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:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
答案 0 :(得分:2)
java.lang.RuntimeException:无法启动活动 ComponentInfo {com.example.cindy.myfirstapp / com.example.cindy.myfirstapp.MainActivity}: java.lang.IllegalStateException:您需要使用Theme.AppCompat 这个活动的主题(或后代)。
日志说明了一切。在Theme.AppCompat
AndroidManifest.xml
答案 1 :(得分:0)
尝试在您的Android清单中导入此行'机器人:主题=" @风格/ AppTheme"':
<application
android:allowBackup="true"
android:icon="@drawable/hub_gcm_100"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
....
</application
并在你的gradle中导入正确的依赖:
compile 'com.android.support:support-v13:23.0.0'
compile 'com.android.support:support-v4:23.0.0'
compile 'com.android.support:appcompat-v7:23.0.0'
告诉我,如果我能帮助你,祝你好运!