`

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

 
阅读更多

今天继续读郭少的<<第一行代码>>,在研究2.4.4体验活动的生命周期,根据书上代码重新敲了一遍,在点击Start DialoyActivity按钮时,程序后台报错,如下:

/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.activityliftcycletest, PID: 4503
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.activityliftcycletest/com.example.activityliftcycletest.DialogActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.support.v7.app.AppCompatDelegateImplV9.createSubDecor(AppCompatDelegateImplV9.java:355)
at android.support.v7.app.AppCompatDelegateImplV9.ensureSubDecor(AppCompatDelegateImplV9.java:324)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:285)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
at com.example.activityliftcycletest.DialogActivity.onCreate(DialogActivity.java:11)
at android.app.Activity.performCreate(Activity.java:6662)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
Application terminated.

我在AndroidManifest.xml中写的是:

 

<activity android:name=".DialogActivity"
android:theme="@android:style/Theme.Dialog">
</activity>

 

根据提示,告诉我下面这句话有问题

android:theme="@android:style/Theme.Dialog"

解决方案有2:

1、将DialogActivity继承类由AppCompatActivity改为Activity

 

2、将android:theme="@android:style/Theme.Dialog"改为
android:theme="@style/Theme.AppCompat.Dialog"

 
分享到:
评论

相关推荐

    android如何设置Activity背景色为透明色

    * 如果继承自 AppCompatActivity,将会报错,例如:java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity。 解决方法是将 Activity 继承自 Activity,...

    详解Android冷启动实现APP秒开的方法

    在采用透明主题时,可能会遇到不兼容的问题,如"java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity."。这通常是因为Activity继承自AppCompatActivity...

    The Book of PF, Second Edition.pdf

    Please keep in mind that this book is intended to show you a few useful techniques and inspire you to achieve good things. Please strive to understand your network and what you need to do to make it...

    Prototype Cheat Sheet

    - **`serialize(formElement[, getHash=false])`**: Serializes a form into a URL-encoded string for use in an AJAX request. - **`serializeElements(elements[, getHash=false])`**: Serializes a collection ...

    RxLib控件包内含RxGIF,全部源码及DEMO

    TRxQuery is a TQuery descendant. It supports macros in the SQL text, which are similar to Params. Macros allow to change query text easily and handy. TSQLScript allows multiple SQL statements in one ...

    rx第三方控件

    TRxQuery is a TQuery descendant. It supports macros in the SQL text, which are similar to Params. Macros allow to change query text easily and handy. TSQLScript allows multiple SQL statements in one ...

    Jquery各种手册

    2. 层次选择器:`后代选择器(ancestor descendant)、子元素选择器(parent &gt; child)、相邻兄弟选择器(+ element)、后续兄弟选择器(~ element)`。 3. 特性选择器:`[attribute]、[attribute=value]、[attribute^=...

    SQLMemTable for Delphi / C++ Builder

    SQLMemTable for Delphi / C++ Builder: README============================================Please read this file carefully (especially the INSTALLATION chapter) before installing the program to your ...

    六级1000关键词汇

    - 例句:A vigorous exercise routine improves overall health. 41. **productive** [prE5dQktIv] *a.* 多产的;富饶的 - 例句:Productive farms produce large amounts of crops each season. 42. **fancy** ...

    英语写作好词替换

    - **例句**:“He is the offspring of a famous writer.” 更加文雅的说法是 “He is a descendant of a renowned author.” #### 4. inevitable -&gt; dispensable - **注意**:这里的“dispensable”似乎与...

    TMS6.8.2.0

    - creating a descendant compiled product such as OCX or ActiveX control and sell or distribute this as a product - using the control in applications sold with different publisher name than the ...

    Clever Internet Suite (SRC) v9.1.0.0

    These Internet components give you everything you need to jumpstart your Internet development without any external dependencies. The suite of Internet Components contain over fifty components which ...

    在学期间html前端知识总结

    1. 后代选择器(`ancestor descendant`):选择祖先元素内的后代元素。 2. 子元素选择器(`parent &gt; child`):选择父元素的直接子元素。 3. 相邻兄弟选择器(`element + element`):选择紧接在另一个元素后的元素...

    vue-removed-hook-mixin:向 Vue 组件添加一个 `removed` 钩子,在 `$el` 从 DOM 中移除后调用

    vue-removed-hook-mixin 向组件添加一个removed... // this.$el is no longer a descendant of document.body. } } // 2) Apply the mixin to all components. import addRemovedHook from "vue-removed-hook-mixi

    DescendantFocusabilityTest.rar_Descendant

    在Android开发中,焦点管理是构建用户界面时一个至关重要的部分。`DescendantFocusability`是Android布局中处理子视图焦点转移的一个属性,它决定了一个父布局如何处理其子视图之间的焦点移动。这个属性主要用在如`...

    wordpress_Descendant_wodpress_

    WordPress is a blog publishing system written in the PHP programming language and using a MySQL database. WordPress is the official descendant of b2 / cafelog

    DIZipWriter v5.5.0 Full Sources

    DIZipWriter outputs all data to the archive straight away, with no need for temporary storage: It does not create any temporary files and does not use huge amount of memory for buffering. It is ...

    jQuery完全实例.rar

    Returning 'true' from within the loop skips to the next iteration (this is like using a 'continue' with a normal loop). 返回值 jQuery 参数 callback (Function) : 对于每个匹配的元素所要执行的函数 ...

    Tusers.Security.Component.v2.0.0.3.For.BCB6.Cracked

    Also, a new design for the User Administration Module with more features and easier to use. The new Automatic Audit feature allows the developer to trace any changes in the datasets (deleted records,...

    RIA应用开发实验指导书:实验一 jQuery选择器.doc

    2. **层级选择器**:`$("ancestor descendant")`选取祖先元素下的子孙元素,`$("parent &gt; child")`选取父元素直接的子元素,`$("prev + next")`选取紧接在前一个元素后面的元素,`$("prev ~ siblings")`选取前一个...

Global site tag (gtag.js) - Google Analytics