简体   繁体   English

为什么在Android Studio中出现与主题相关的错误?

[英]why am I getting an Theme related error in android studio?

I am following a tutorial on how to make a launcher but for some reason when I add this line of code to my main activity with in the manifest the app crashes saying that my app has stopped 我正在关注如何制作启动器的教程,但是由于某种原因,当我将这行代码添加到我的主要活动中时,清单中的应用崩溃,表明我的应用已停止

 android:theme="@android:style/Theme.Holo.Wallpaper.NoTitleBar" 

 10-18 15:04:25.245 18122-18122/com.example.harrops.h20droidlauncher E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: com.example.harrops.h20droidlauncher, PID: 18122 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.harrops.h20droidlauncher/com.example.harrops.h20droidlauncher.HomeLayout}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2400) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2458) at android.app.ActivityThread.access$900(ActivityThread.java:172) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1305) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:146) at android.app.ActivityThread.main(ActivityThread.java:5598) 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:1283) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099) 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.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.harrops.h20droidlauncher.HomeLayout.onCreate(HomeLayout.java:13) at android.app.Activity.performCreate(Activity.java:5459) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2458)            at android.app.ActivityThread.access$900(ActivityThread.java:172)            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1305)            at android.os.Handler.dispatchMessage(Handler.java:102)            at android.os.Looper.loop(Looper.java:146)            at android.app.ActivityThread.main(ActivityThread.java:5598)            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:1283)            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)            at dalvik.system.NativeStart.main(Native Method) 

if I remove the line of code the app runs just fine. 如果我删除代码行,则该应用程序运行正常。

Any help would be great. 任何帮助都会很棒。 Thanks as always in advance. 一如既往地感谢您。

To change the Background use: 要更改背景使用:

 android:background=" "

You selected a wallpaper. 您选择了墙纸。

Try this instead 试试这个

android:background="#b6db49">

Below you have said that you want to use the theme. 在下面您已经说过要使用主题。 So you have to go in the manifest and edit the theme there which is 因此,您必须进入清单并在其中编辑主题

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Holo.Wallpaper.NoTitleBar">

If You've begun Your project in Android Studio by default main activity extends ActionBarActivity which requires the AppCompat theme. 如果您已经开始在默认情况下在Android Studio中进行项目,则主活动将扩展ActionBarActivity ,该动作需要AppCompat主题。 Change the Java inheritance from ActionBarActivity to Activity and leave the theme in the manifest as it is. 将Java继承从ActionBarActivity更改为Activity ,并将主题保留在清单中。 Or use AppCompat theme. 或使用AppCompat主题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我在使用 android studio 时会出现此错误。? - Why am I getting this error while using android studio.? 为什么在Android Studio中的SearchView和OnQueryTextListener上出现此错误? - Why am I getting this error in Android Studio on SearchView and OnQueryTextListener? 为什么在Android Studio中出现此错误 - Why am getting this error in android studio 我在android studio上遇到了奇怪的错误 - I am getting strange error on android studio Android:为什么会出现此错误? - Android: Why am i getting this error? 为什么在 Android Studio 中创建新项目时出现以下错误? - Why am I getting following error while I create a new project in Android studio? 为什么我收到“错误检索项目的父项:找不到与给定名称匹配的资源&#39;@android:style / Theme.Dialog.Alert&#39;”? - Why am I getting a “Error Retrieving parent for item: No resource found that matches the given name '@android:style/Theme.Dialog.Alert'”? Android Studio:为什么我在全新的 Google Maps API 项目上出现多 dex 错误? - Android Studio: Why am i getting multi dex error on brand new Google Maps API project? 为什么我尝试在 android studio 中打开新活动时出错 - why am i getting error when trying to open new activity in android studio 为什么在Android Studio中出现此错误“原始类型的预期资源”? - Why am I getting this error “Expected resource of type raw” in Android Studio?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM