Android Question RunTimePermissions problem - suddenly

msains

Member
Licensed User
Longtime User
I'm a bit embarrased that I can't solve this sudden new error....

I've checked out the answers to a similar query in this forum but I don't see where I'm
going wrong - even using those discussions and bits of advice from the experts

I'm not a Java coder at all
After upgrading to B4A 10.2 I now (suddenly) get an error around RunTimePermissions

I'm running against Android SDK 28
The Manifest lists the SDK version required as 28

I also use the SDK for a C# Xamarin Project in a separate universe

The Code fails on Line 3 (below)
Code is:
Sub TestPermissions() As Boolean
    Dim RTP As  RuntimePermissions
    Dim OK As Boolean = RTP.Check(RTP.PERMISSION_WRITE_EXTERNAL_STORAGE)
    Return OK
End Sub

Error is ....

** Activity (main) Create, isFirst = true **
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/core/content/ContextCompat;
    at anywheresoftware.b4a.objects.RuntimePermissions.Check(RuntimePermissions.java:73)
    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:348)
    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 anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:262)
    at OwlIT.OwlRover.main._testpermissions(main.java:1522)
    at OwlIT.OwlRover.main._activity_create(main.java:1338)
    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 OwlIT.OwlRover.main.afterFirstLayout(main.java:105)
    at OwlIT.OwlRover.main.access$000(main.java:17)
    at OwlIT.OwlRover.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:201)
    at android.app.ActivityThread.main(ActivityThread.java:6826)
    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:873)
Caused by: java.lang.ClassNotFoundException: Didn't find class "androidx.core.content.ContextCompat" on path: DexPathList[[zip file "/data/app/OwlIT.OwlRover--bWWGtiBU1N3ZVG0M6Yp4g==/base.apk"],nativeLibraryDirectories=[/data/app/OwlIT.OwlRover--bWWGtiBU1N3ZVG0M6Yp4g==/lib/arm, /system/lib, /vendor/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    ... 27 more
Error occurred on line: 569 (Main)
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Boolean.booleanValue()' on a null object reference
    at OwlIT.OwlRover.main._testpermissions(main.java:1522)
    at OwlIT.OwlRover.main._activity_create(main.java:1338)
    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 OwlIT.OwlRover.main.afterFirstLayout(main.java:105)
    at OwlIT.OwlRover.main.access$000(main.java:17)
    at OwlIT.OwlRover.main$WaitForLayout.run(main.java:83)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:201)
    at android.app.ActivityThread.main(ActivityThread.java:6826)
    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:873)
Error occurred on line: 570 (Main)
java.lang.Exception: array not expected...

Javac Path is .... C:\Program Files\Java\jdk1.8.0_172\bin\javac.exe
Android Jar is ... C:\Users\msains\AppData\Local\Android\android-sdk\platforms\android-28\android.jar
Additional Libraries ... C:\Development\Basic4Android\AdditionalLibraries

Is there something obvious here that I'm missing ?
(be kind)
 

RichardN

Well-Known Member
Licensed User
Longtime User
Your variable RTP needs to be declared in Process Globals.

Also better to test for the RTP in a Resumable Sub before the first call to use the permission. Additionally that's not the correct method for checking the permission result. Checkout the tutorial for the correct method.
 
Last edited:
Upvote 0
Top