Android Question B4xdrawer example error

Discussion in 'Android Questions' started by SayCheese, Aug 12, 2019.

  1. SayCheese

    SayCheese Member Licensed User

    As a newbee to B4A, Java and Android programming even running a example file can be frustrating even after hours trying to figure out where I did something wrong in the installation process. I'm trying the B4Xdrawer example provided in [B4X] B4XDrawer - sliding drawer.

    I did the following:
    • Added the B4XDrawer.bas module
    • Added the library AppCompat (although the "AppCompat with ToolBar" example didn't work either, so the errors probably are related to AppCompat).
    • Added libraries ViewsEx v1.30+ and XUI v1.90.
    Compiling is oke but running in DBug mode I got this error:

    ** Activity (main) Create, isFirst = true **
    Error occurred on line: 217 (B4XDrawer)
    java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:170)
    at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
    at anywheresoftware.b4a.objects.B4XViewWrapper.LoadLayout(B4XViewWrapper.java:292)
    at b4a.example.main._activity_create(main.java:391)
    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:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)

    Line 217 is from the example project
    Code:
    Public Sub getCenterPanel As B4XView
        
    Return mCenterPanel
    End Sub
    Any help is appreciated.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Start with running the example as is. Does it work for you?
     
  3. SayCheese

    SayCheese Member Licensed User

    "As is" means just open the example project and hit F5?
    No it fails to run with the error although is compiles.
     
  4. SayCheese

    SayCheese Member Licensed User

    Btw without the appcompat library it does not compile. So at least I think I have to install this library?
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Yes.

    Please post the full error message.

    You do need to copy the libraries files to the additional libraries folder.

    Are you using B4A v9.3?
     
  6. SayCheese

    SayCheese Member Licensed User

    Yes I'm using the v9.30.

    It seems that I'm missing some library I'm not aware of. I don't know how to get them although I have tried to struggle with the information the SDKmanager provides.

    *** Service (starter) Create ***
    ** Service (starter) Start **
    ** Activity (main) Create, isFirst = true **
    main_activity_create (java line: 349)
    java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:170)
    at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
    at anywheresoftware.b4a.objects.B4XViewWrapper.LoadLayout(B4XViewWrapper.java:292)
    at b4a.example.main._activity_create(main.java:349)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
    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:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6694)
    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.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)
    ... 15 more
    Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/widget/Toolbar;
    at b4a.example.main._globals(main.java:411)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
    at b4a.example.main.initializeGlobals(main.java:320)
    at b4a.example.main.afterFirstLayout(main.java:101)
    ... 9 more
    Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.Toolbar" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/b4a.example-LO8UogOVgVkS6G9dS7WqJA==/base.apk"],nativeLibraryDirectories=[/data/app/b4a.example-LO8UogOVgVkS6G9dS7WqJA==/lib/arm64, /system/lib64, /vendor/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    ... 14 more
    ** Activity (main) Resume **
    ** Activity (main) Pause, UserClosed = true **
    ** Activity (main) Create, isFirst = false **
    ** Activity (main) Resume **
    ** Activity (main) Pause, UserClosed = true **
    ** Activity (main) Create, isFirst = false **
    ** Activity (main) Resume **
    ** Activity (main) Pause, UserClosed = false **
     
  7. Peter Simpson

    Peter Simpson Expert Licensed User

    @SayCheese are you using AppCompat 4.00 and have you jetified the library?

    IDE > Tools > Jetifier (AndroidX)?

    Then try running the project again...
     
  8. SayCheese

    SayCheese Member Licensed User

    AppCompat v3.52 and I just ran Jetifier but the error remains.
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    Make sure to clean the project after running Jetifier (Ctrl + P).
     
  10. SayCheese

    SayCheese Member Licensed User

    I ran 'Jetifier (AndroidX)' and 'Clean project'. Still no succes
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    Can you post the compilation window text?
     
  12. SayCheese

    SayCheese Member Licensed User

    B4A Version: 9.30
    Java Version: 8
    Parsing code. (0.01s)
    Building folders structure. (0.07s)
    Compiling code. (0.04s)
    Compiling layouts code. (0.01s)
    Organizing libraries. (0.00s)
    (AndroidX SDK)
    Generating R file. (0.00s)
    Compiling generated Java code. (0.07s)
    Convert byte code - optimized dex. (1.89s)
    Packaging files. (1.90s)
    Copying libraries resources (0.00s)
    Signing package file (debug key). (1.48s)
    ZipAlign file. (0.16s)
    Installing file to device. (4.02s)
    Device serial: 53ea683d0305
    Completed successfully.
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    This means that the library was not jetified properly. My guess is that you copied AppCompat to the internal libraries folder instead of the additional libraries folder.
     
  14. Peter Simpson

    Peter Simpson Expert Licensed User

    Last edited: Aug 12, 2019
  15. SayCheese

    SayCheese Member Licensed User

    It is in the Additional Libraries although it seems a bit old

    upload_2019-8-12_16-8-5.png

    upload_2019-8-12_16-10-2.png
     
  16. Erel

    Erel Administrator Staff Member Licensed User

    You should have seen an error message when you tried to jetify the libraries. The additional libraries folder should never be under Program Files, as that is a restricted folder.
     
    Peter Simpson likes this.
  17. SayCheese

    SayCheese Member Licensed User

    Installed AppCompatv4.0

    upload_2019-8-12_16-15-42.png

    Ran Jetifier and cleaned the project.....still no succes.

    Copying updated assets files (3)
    *** Service (starter) Create ***
    ** Service (starter) Start **
    ** Activity (main) Create, isFirst = true **
    Error occurred on line: 217 (B4XDrawer)
    java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
    at anywheresoftware.b4a.keywords.LayoutBuilder.loadLayout(LayoutBuilder.java:170)
    at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:134)
    at anywheresoftware.b4a.objects.B4XViewWrapper.LoadLayout(B4XViewWrapper.java:292)
    at b4a.example.main._activity_create(main.java:391)
    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:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6694)
    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.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)
    ... 19 more
    Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v7/widget/Toolbar;
    at java.lang.Class.classForName(Native Method)
    at java.lang.Class.forName(Class.java:453)
    at java.lang.Class.forName(Class.java:378)
    at anywheresoftware.b4a.shell.Shell.getCorrectClassName(Shell.java:624)
    at anywheresoftware.b4a.shell.Shell.createObject(Shell.java:611)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:366)
    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.initializeGlobals(main.java:320)
    at b4a.example.main.afterFirstLayout(main.java:101)
    ... 9 more
    Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.Toolbar" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/b4a.example-9UdHONTNSNfqBW5yP-sCrg==/base.apk"],nativeLibraryDirectories=[/data/app/b4a.example-9UdHONTNSNfqBW5yP-sCrg==/lib/arm64, /system/lib64, /vendor/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    ... 20 more
    ** Activity (main) Resume **

    What about the error
    Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v7.widget.Toolbar" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/b4a.example-9UdHONTNSNfqBW5yP-sCrg==/base.apk"],nativeLibraryDirectories=[/data/app/b4a.example-9UdHONTNSNfqBW5yP-sCrg==/lib/arm64, /system/lib64, /vendor/lib64]]
     
  18. Erel

    Erel Administrator Staff Member Licensed User

    Please see my previous post.
     
  19. SayCheese

    SayCheese Member Licensed User

    Yes, I read them and changed the locations of both the Additional libraries and Shared Folder.
    This time it ran without any problems.

    You gentlemen have both been very patient. Thank you for your help.

    If I may do a suggestion:
    If the Jetifier runs into an error (because of the bad locations of the 2 read only folders) perhaps it's a good idea to let the user know. I Only saw a window popping up for a split second. I didn't know what to expect from the jetifier so I assumed this was oke.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice