错误记录Android 应用运行报错 ( You need to use a Theme.AppCompat theme (or descendant) with this activity. )(代
Posted 韩曙亮
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了错误记录Android 应用运行报错 ( You need to use a Theme.AppCompat theme (or descendant) with this activity. )(代相关的知识,希望对你有一定的参考价值。
一、报错信息
运行 android 应用时 , 报错 ;
报错信息如下 :
2021-08-04 21:04:12.067 26338-26338/com.example.plugin_hook E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.plugin_hook, PID: 26338
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.plugin_hook/com.example.plugin_hook.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2951)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3086)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6718)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
at androidx.appcompat.app.AppCompatDelegateImpl.createSubDecor(AppCompatDelegateImpl.java:846)
at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:809)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:696)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:195)
at com.example.plugin_hook.MainActivity.onCreate(MainActivity.java:24)
at android.app.Activity.performCreate(Activity.java:7144)
at android.app.Activity.performCreate(Activity.java:7135)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2931)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3086)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6718)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
二、解决方案
错误原因 : 使用了自定义 Application 之后 , 出现上述问题 ;
解决方案一 : 按照错误提示进行修改 ;
错误信息中 , 给出了解决方案提示 , You need to use a Theme.AppCompat theme (or descendant) with this activity.
使用 Theme.AppCompat 主题即可 ;
( 该方法可能无法生效 )
解决方案二 : 令 MainActivity 继承自 android.app.Activity ;
public class MainActivity extends Activity {
以上是关于错误记录Android 应用运行报错 ( You need to use a Theme.AppCompat theme (or descendant) with this activity. )(代的主要内容,如果未能解决你的问题,请参考以下文章
错误记录Android Studio 编译报错 ( Android Gradle plugin requires Java 11 to run. You are currently using )
错误记录编译 Android 版本的 ijkplayer 报错 ( You must define ANDROID_NDK before starting. | 下载指定版本 NDK )
错误记录Android 应用运行报错 ( java.lang.VerifyError: Verifier rejected class androidx. | 逆向中遇到的问题 )
错误记录Android Studio 真机运行 Apk 应用报错 ( The application could not be installed: SHELL_UNRESPONSIVE )
错误记录应用运行 CPU 占用率达到 90% ( 使用 CPU Profiler 监控应用运行情况 )
错误记录Android 应用执行报错 ( java.lang.UnsatisfiedLinkError: dalvik.system.PathClassLoader[DexPathList[[ )