Android Question this error occured sometimes

khosrwb

Active Member
Licensed User
Longtime User
I will make own file manager
when I run this code I get error , this error occured sometimes , I think error is other but b4a show in this line
this is my mistake or ( bug ) ?!!



B4X:
Sub listfile
    C1 = 0
    List1.Initialize
    List1.Clear
    List1 = File.ListFiles(addrss)
    C = List1.Size  
    
    timer2.Enabled = True

    List1.Sort(True)   
    List2.Initialize
    List2.Clear   
    List3.Initialize
    List3.Clear
    Listview1.Clear
    
    For i =0 To List1.Size - 1
        ii = i
        s1 = List1.Get(i)
        A = s1.Length   
        st3 = s1           
        fileformat
Listview1.AddTwoLinesAndBitmap2(List1.Get(i),s3,LoadBitmap(File.DirAssets,"co8.png"),List1.Get(i))     
    Next   
    Log(addrss)
    Activity.Title = addrss
    label1.Text =List2.Size &" / "& Listview1.Size &" / "& List1.Size &" / "& (i+1)
End Sub


( I initialize list1 but sometimes I get this error ) you can see in down picture
my phone is j7 pro with android 7

excuseme if my english isn't good
 

Attachments

  • Captur.PNG
    Captur.PNG
    104.2 KB · Views: 185

Jorge M A

Well-Known Member
Licensed User
Longtime User
a) Somewhere in your code you have DIM C as Int?
b) You aren't using C variable in the shown code, can you delete it?
c) Try changing the name of variable C to another identifier such as Cx. (I have faced strange problems in other languages when using identifier C)
 
Upvote 0

khosrwb

Active Member
Licensed User
Longtime User
a) Somewhere in your code you have DIM C as Int?
b) You aren't using C variable in the shown code, can you delete it?
c) Try changing the name of variable C to another identifier such as Cx. (I have faced strange problems in other languages when using identifier C)

hi Jorge M A
thanks but my problem is with ( List1.Initialize )
this isn't important ; I remove it but I have this error

thanks Jorge M A

you can see log error here :

Error occurred on line: 214 (Main)
java.lang.RuntimeException: Object should first be initialized (List). :confused::confused::confused::confused: I initialize list :mad:

at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at anywheresoftware.b4a.objects.collections.List.getSize(List.java:129)
at b4a.example.main._listfile(main.java:851)
at b4a.example.main._btninternalstorage_click(main.java:1170)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
at android.view.View.performClick(View.java:6261)
at android.widget.TextView.performClick(TextView.java:11159)
at android.view.View$PerformClick.run(View.java:23752)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)

I think b4a show incorrect error and I have mistake in another place
 
Last edited:
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Check this:

Method_636.png
File. ListFiles (Dir As String) As List

Returns a read only list with all the files and directories which are stored in the specified path.
An uninitialized list will be returned if the folder is not accessible.
 
Upvote 0
Top