Android The style on this component requires your app theme to be Theme.AppCompat

赵雅懿
2023-12-01

 

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.debugshow, PID: 3438
    java.lang.RuntimeException: Unable to start service com.example.debugshow.view.Main.FloatingService@ed88d6d with Intent { cmp=com.example.debugshow/.view.Main.FloatingService (has extras) }: android.view.InflateException: Binary XML file line #22: Binary XML file line #22: Error inflating class com.example.debugshow.view.Main.DraggableFloatingButton
        at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3097)
        at android.app.ActivityThread.access$2300(ActivityThread.java:156)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1507)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:157)
        at android.app.ActivityThread.main(ActivityThread.java:5653)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:746)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
     Caused by: android.view.InflateException: Binary XML file line #22: Binary XML file line #22: Error inflating class com.example.debugshow.view.Main.DraggableFloatingButton
        at android.view.LayoutInflater.inflate(LayoutInflater.java:543)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
        at android.view.View.inflate(View.java:19830)
        at com.example.debugshow.view.Main.FloatingDebugView.initView(FloatingDebugView.java:37)
        at com.example.debugshow.view.Main.FloatingDebugView.<init>(FloatingDebugView.java:31)
        at com.example.debugshow.view.Main.FloatingDebugWindowManager.addView(FloatingDebugWindowManager.java:52)
        at com.example.debugshow.view.Main.FloatingService.onStartCommand(FloatingService.java:41)
        at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3077)
        at android.app.ActivityThread.access$2300(ActivityThread.java:156) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1507) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:157) 
        at android.app.ActivityThread.main(ActivityThread.java:5653) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:746) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636) 
     Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class com.example.debugshow.view.Main.DraggableFloatingButton
        at android.view.LayoutInflater.createView(LayoutInflater.java:649)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:768)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:708)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:839)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:842)
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:519)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:427) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
        at android.view.View.inflate(View.java:19830) 
        at com.example.debugshow.view.Main.FloatingDebugView.initView(FloatingDebugView.java:37) 
        at com.example.debugshow.view.Main.FloatingDebugView.<init>(FloatingDebugView.java:31) 
        at com.example.debugshow.view.Main.FloatingDebugWindowManager.addView(FloatingDebugWindowManager.java:52) 
        at com.example.debugshow.view.Main.FloatingService.onStartCommand(FloatingService.java:41) 
        at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3077) 
        at android.app.ActivityThread.access$2300(ActivityThread.java:156) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1507) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:157) 
        at android.app.ActivityThread.main(ActivityThread.java:5653) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:746) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636) 
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Constructor.newInstance(Native Method)
        at android.view.LayoutInflater.createView(LayoutInflater.java:623)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:768) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:708) 
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:839) 
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802) 
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:842) 
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:519) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:427) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
        at android.view.View.inflate(View.java:19830) 
        at com.example.debugshow.view.Main.FloatingDebugView.initView(FloatingDebugView.java:37) 
        at com.example.debugshow.view.Main.FloatingDebugView.<init>(FloatingDebugView.java:31) 
        at com.example.debugshow.view.Main.FloatingDebugWindowManager.addView(FloatingDebugWindowManager.java:52) 
        at com.example.debugshow.view.Main.FloatingService.onStartCommand(FloatingService.java:41) 
        at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3077) 
        at android.app.ActivityThread.access$2300(ActivityThread.java:156) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1507) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:157) 
        at android.app.ActivityThread.main(ActivityThread.java:5653) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:746) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636) 
     Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.AppCompat (or a descendant).
        at android.support.design.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:221)
        at android.support.design.internal.ThemeEnforcement.checkAppCompatTheme(ThemeEnforcement.java:196)
        at android.support.design.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:131)
        at android.support.design.internal.ThemeEnforcement.obtainStyledAttributes(ThemeEnforcement.java:72)
        at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:195)
        at android.support.design.widget.FloatingActionButton.<init>(FloatingActionButton.java:188)
        at com.example.debugshow.view.Main.DraggableFloatingButton.<init>(DraggableFloatingButton.java:24)
        at java.lang.reflect.Constructor.newInstance(Native Method) 
        at android.view.LayoutInflater.createView(LayoutInflater.java:623) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:768) 
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:708) 
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:839) 
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802) 
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:842) 
        at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:802) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:519) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:427) 
        at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
        at android.view.View.inflate(View.java:19830) 
        at com.example.debugshow.view.Main.FloatingDebugView.initView(FloatingDebugView.java:37) 
        at com.example.debugshow.view.Main.FloatingDebugView.<init>(FloatingDebugView.java:31) 
        at com.example.debugshow.view.Main.FloatingDebugWindowManager.addView(FloatingDebugWindowManager.java:52) 
        at com.example.debugshow.view.Main.FloatingService.onStartCommand(FloatingService.java:41) 
        at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3077) 
        at android.app.ActivityThread.access$2300(ActivityThread.java:156) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1507) 
        at android.os.Handler.dispatchMessage(Handler.java:102) 
        at android.os.Looper.loop(Looper.java:157) 
        at android.app.ActivityThread.main(ActivityThread.java:5653) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:746) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636) 
I/Process: Sending signal. PID: 3438 SIG: 9
Disconnected from the target VM, address: 'localhost:8600', transport: 'socket'

       网上很多说法是出这个错的原因是自定义View的构造函数没写全,但是我把三个构造函数写全了,依然报这个错。其实真正的解法是,在引用这个自定义布局的界面根标签里,添加一行代码:

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

 

 

 类似资料:

相关阅读

相关文章

相关问答