Android Question Design Support Library error

GGSoft

Member
Licensed User
Longtime User
Today I did switch to AndroidX SDK. Testing some of my projects I got an error with the Design Support Library. I isolated the problem in a simple project. This is the error I get:
B4X:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Error occurred on line: 31 (Main)
java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:170)
    at anywheresoftware.b4a.objects.ActivityWrapper.LoadLayout(ActivityWrapper.java:209)
    at b4a.example.main._activity_create(main.java:383)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at b4a.example.main.afterFirstLayout(main.java:104)
    at b4a.example.main.access$000(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:82)
    at android.os.Handler.handleCallback(Handler.java:789)
    at android.os.Handler.dispatchMessage(Handler.java:98)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6944)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
Caused by: java.lang.reflect.InvocationTargetException
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.objects.CustomViewWrapper.AfterDesignerScript(CustomViewWrapper.java:64)
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:162)
    ... 18 more
Caused by: java.lang.IllegalArgumentException: The style on this component requires your app theme to be Theme.AppCompat (or a descendant).
    at com.google.android.material.internal.ThemeEnforcement.checkTheme(ThemeEnforcement.java:221)
    at com.google.android.material.internal.ThemeEnforcement.checkAppCompatTheme(ThemeEnforcement.java:196)
    at com.google.android.material.internal.ThemeEnforcement.checkCompatibleTheme(ThemeEnforcement.java:131)
    at com.google.android.material.internal.ThemeEnforcement.obtainStyledAttributes(ThemeEnforcement.java:72)
    at com.google.android.material.tabs.TabLayout.<init>(TabLayout.java:417)
    at com.google.android.material.tabs.TabLayout.<init>(TabLayout.java:399)
    at com.google.android.material.tabs.TabLayout.<init>(TabLayout.java:395)
    at de.amberhome.objects.TabLayoutWrapper.innerInitialize(TabLayoutWrapper.java:59)
    at anywheresoftware.b4a.objects.ViewWrapper.Initialize(ViewWrapper.java:67)
    at de.amberhome.objects.TabLayoutWrapper.Initialize(TabLayoutWrapper.java:52)
    at de.amberhome.objects.TabLayoutWrapper._initialize(TabLayoutWrapper.java:90)
    ... 21 more
** Activity (main) Resume **

A simple project is attached.

Any advice?
 

Attachments

  • DesignSupportErr.zip
    9.2 KB · Views: 293

Erel

B4X founder
Staff member
Licensed User
Longtime User
Based on the error message you need to:
1. Add a reference to AppCompat.
2. Add:
B4X:
#Extends: android.support.v7.app.AppCompatActivity
And set an AppCompat theme:
3.
B4X:
SetApplicationAttribute(android:theme, "@style/MyAppTheme")

CreateResource(values, theme.xml,
<resources>
    <style name="MyAppTheme" parent="Theme.AppCompat.NoActionBar">
    </style>
</resources>
)
 
Upvote 0

GGSoft

Member
Licensed User
Longtime User
Thank you for your quick response. Actually what happened is that I was using the obsolete SDK Manager. I migrated to the one recommended by B4A and now everything is up and running.
 
Upvote 0
Top