Android Question File.ListFiles behaving unexpectedly

sugemd

Member
my code like this:

my code:
Dim lstFile As List=File.ListFiles(File.DirInternal & "/Pldata")
lstFile.Sort(True)

error happen:

error:
java.lang.RuntimeException: Object should first be initialized (List).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
    at anywheresoftware.b4a.objects.collections.List.Sort(List.java:144)
    at pldata.check.clswebnewfile._refreshfilelist(clswebnewfile.java:885)
    at pldata.check.clswebnewfile._btnmag_click(clswebnewfile.java:89)
    at pldata.check.clswebnewfile.callSub(clswebnewfile.java:959)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1066)
    at anywheresoftware.b4a.keywords.Common.CallSubNew3(Common.java:1045)
    at pldata.check.clswebmain._m_webview_pagefinished(clswebmain.java:1249)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:213)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.objects.WebViewWrapper$1.onPageFinished(WebViewWrapper.java:60)
    at JA0.b(chromium-TrichromeWebViewGoogle.apk-stable-460608533:2)
    at P9.handleMessage(chromium-TrichromeWebViewGoogle.apk-stable-460608533:61)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:247)
    at android.app.ActivityThread.main(ActivityThread.java:8676)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130)

i can't find reason.
please help me ,thanks!
 

sugemd

Member
but i create dir before read list file,like this:
B4A:
If File.Exists(File.DirInternal, "/Pldata") = False Then
        File.MakeDir(File.DirInternal, "/Pldata")
End If

Dim lstFile As List=File.ListFiles(File.DirInternal & "/Pldata")
lstFile.Sort(True)

error still happen ,why?
 
Upvote 0

teddybear

Well-Known Member
Licensed User
The code you post is correct, if the folder is not existed, error xxx is not a folder. the RuntimeException should be some code else
 
Upvote 0
Top