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

简介: You need to use a Theme.AppCompat theme (or descendant) with this activity

具体错误

2021-11-01 20:03:17.567 14095-14095/com.serenegiant.usbcameratest E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.serenegiant.usbcameratest, PID: 14095
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.serenegiant.usbcameratest/com.serenegiant.usbcameratest.MainActivity}: java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3483)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3655)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2108)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:236)
        at android.app.ActivityThread.main(ActivityThread.java:7879)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:656)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:967)
     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:696)
        at androidx.appcompat.app.AppCompatDelegateImpl.ensureSubDecor(AppCompatDelegateImpl.java:659)
        at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:552)
        at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:161)
        at com.serenegiant.usbcameratest.MainActivity.onCreate(MainActivity.java:63)


解决办法一

由继承自AppCompatActivity改为继承自Activity


解决办法二

第一步:在当前应用的build.gradle,添加红色加粗这两句:


dependencies {


   compile 'com.android.support:design:25.0.0'

   compile 'com.android.support.constraint:constraint-layout:1.0.0-beta5'

}

第二步:在对应的activity中添加红色加粗这一句:


<activity android:name="net.quantum6.MainActivity"

   android:windowSoftInputMode="stateHidden|adjustPan"

   android:theme="@style/AppThemeQuantum6"

   android:screenOrientation="portrait"

   >

第三步:在style.xml添加红色加粗这三句:


<style name="AppThemeQuantum6" parent="Theme.AppCompat.Light.DarkActionBar">

   <!-- Customize your theme here. -->

</style>

目录
相关文章
|
18天前
|
XML API Android开发
android上FragmentTabHost实现自定义Tab Indicator
android上FragmentTabHost实现自定义Tab Indicator
18 1
|
开发工具 Android开发
细说 AppCompat 主题引发的坑:You need to use a Theme.AppCompat theme with this activity!
细说 AppCompat 主题引发的坑:You need to use a Theme.AppCompat theme with this activity!
细说 AppCompat 主题引发的坑:You need to use a Theme.AppCompat theme with this activity!
|
Android开发
【错误记录】Android 应用运行报错 ( You need to use a Theme.AppCompat theme (or descendant) with this activity. )
【错误记录】Android 应用运行报错 ( You need to use a Theme.AppCompat theme (or descendant) with this activity. )
525 0
【错误记录】Android 应用运行报错 ( You need to use a Theme.AppCompat theme (or descendant) with this activity. )
|
Android开发
You need to use a Theme.AppCompat theme (or descendant) with this activity
You need to use a Theme.AppCompat theme (or descendant) with this activity
213 0
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this a
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this a
|
XML Android开发 数据格式