美文网首页
Caused by: java.lang.IllegalArgu

Caused by: java.lang.IllegalArgu

作者: 没有了遇见 | 来源:发表于2021-10-22 16:42 被阅读0次

    MaterialCardView 使用BUG

    android.view.InflateException: Binary XML file line #118: Binary XML file line #118: Error inflating class com.google.android.material.card.MaterialCardView
    Caused by: android.view.InflateException: Binary XML file line #118: Error inflating class com.google.android.material.card.MaterialCardView
    Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance0(Native Method)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:343)
        at android.view.LayoutInflater.createView(LayoutInflater.java:651)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:794)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:867)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:870)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:870)
        at 
    ....
    androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:95)
        at com.wu.common.base.ui.fragment.MvpBaseFragment.onCreateView(MvpBaseFragment.java:32)
        at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2600)
        at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:881)
        at android.view.Choreographer.doCallbacks(Choreographer.java:839)
        at android.view.Choreographer.doFrame(Choreographer.java:774)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1030)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:207)
        at android.app.ActivityThread.main(ActivityThread.java:6878)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:876)
     Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.MaterialComponents (or a descendant).
        at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:243)
        at com.google.android.material.internal.ThemeEnforcement.checkMaterialTheme(ThemeEnforcement.java:217)
        at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:145)
        at com.google.android.material.internal.ThemeEnforcement.obtainStyledAttributes(ThemeEnforcement.java:76)
        at com.google.android.material.card.MaterialCardView.<init>(MaterialCardView.java:123)
        at com.google.android.material.card.MaterialCardView.<init>(MaterialCardView.java:113)
            ... 74 more
    

    原因: 引用了 MaterialTheme 的资源所以必须引用MaterialTheme的Theme

    image.png image.png

    解决:MaterialCardView 所以的Activity 引用Theme.MaterialComponents下的Theme

    image.png
     <activity
            android:name=".module.main.ui.activity.MainActivity"
            android:theme="@style/Theme.MaterialComponents.Light.NoActionBar"
            android:configChanges="keyboardHidden|screenSize|orientation|smallestScreenSize|screenLayout"
            android:screenOrientation="portrait"
            android:windowSoftInputMode="stateHidden|adjustResize"
            tools:ignore="LockedOrientationActivity" >
    

    相关文章

      网友评论

          本文标题:Caused by: java.lang.IllegalArgu

          本文链接:https://www.haomeiwen.com/subject/sqqhaltx.html