Android Question [SOLVED] Externalstorage class: java.lang.ClassNotFoundException: android.support$v4$provider$DocumentFile

rosippc64a

Active Member
Licensed User
Longtime User
Hi All,
I would need write to SD card on a phone running android 7.0.
I tried the unmodified Externalstorage class example. After installing the program and selecting one of the directory of the connected pendrive, the program crash with this error message:
java.lang.ClassNotFoundException: android.support$v4$provider$DocumentFile, here:
B4X: Copy
Private Sub GetPickedDir (uri As String) As JavaObject
    Dim DocumentFileStatic As JavaObject
    Dim treeUri As Uri
    treeUri.Parse(uri)
    Dim PickedDir As JavaObject = DocumentFileStatic.InitializeStatic("android.support.v4.provider.DocumentFile").RunMethod("fromTreeUri", Array(ctxt, treeUri))
    Return PickedDir
End Sub
This happen after I run the SDK manager and refreshed all suggested item, because before it I couldn't compile the example.
What do I wrong?
 
i'm not an expert in this, but i believe you need androidx.support.v4.jar in your add'l libraries folder (android.support.v4 no longer supported). if the old android.support.v4.jar is there, i think you only need to "jetify" it in the sdk manager. see what you have there.
i think the old file still may work, but we're not supposed to use it. you should jetify it.

if you don't have either, i think you need to download one or the other from maven, save it to your add'l libraries folder and jetify, if necessary. see this support-v4

i think you also need to reference the .jar in your app (
#AdditionalJar: com.androidx.support:support-v4). i've seen a link here in the forum that says, this step is no longer necessary, but try it. you couldn't be any worse off than you are already,

fyi: i can see your provider.DocumentFile class in the androidx.support.v4.jar file (it's also in the old android.support.v4.jar). so if your app knows where to find it, the call will work.
 
Upvote 0
java.lang.ClassNotFoundException: android.support$v4$provider$DocumentFile, here:
Are you using the old Support artifacts or are you using AndroidX?
Please post your compilationwindowtext.

The external storage class is updated to use the AndroidX Artifacts. Maybe you are using an old version of the class?

Try to update the Class to the newest one. ReDownload the class and implement it in your app. And try again then...
 
Upvote 0
Very interesting, DonManfred.
When I use the latest unmodified example Erel's, with
#AdditionalJar: androidx.legacy:legacy-support-core-utils (jetfy happened months before), the program crashed.
But: I found your older example, with
#AdditionalJar: com.android.support:support-core-utils
the program crashed at
B4X: Copy
    ' define destfile
    Dim destfile As ExternalFile = Storage.CreateNewFile(Test,filetocopy)
, because the Test is null.
But, if I set volume label to the pendrive, your program don't crash in the same device.
Erel's program compile:
1583479835236.png
 
Upvote 0
Now I tried to set empty the pendrive volume label and your program (#AdditionalJar: com.android.support:support-core-utils ) works, but Erel's latest (#AdditionalJar: androidx.legacy:legacy-support-core-utils ) doesn't. So doesn't depend on volume label (I read somewhere error about this).
But Erel's program crashed when I select a folder, even the top-level, the root of the SD card.
 
Upvote 0
I feel some trouble with my android-support-v4.jar, looks old a bit. Is it important?
 
Last edited:
Upvote 0
Yess, when I take Erel latest example, what crashed at me, and change the
#AdditionalJar: androidx.legacy:legacy-support-core-utils
to
#AdditionalJar: com.android.support:support-core-utils
the program works well. So my computer has problem with androidx.legacy:legacy-support-core-utils. But no sign in compile time, jetify is ok, all suggested lib refreshed in SDK - just I am not a clever enough :-(

Aha, my B4a don't looks using AndroidX SDK.

I am on installing new Android SDK.
*************************************************
After installing the new SDK, all thing works well.
I was skipper, I didn't think the time would come so quickly when I needed to AndroidX.

Thank you DonManfred and drgottjr!!
 
Last edited:
Upvote 0
Back
Top