Android Question list.initialize runs in Debug not in Release

koffie

Member
Licensed User
Longtime User
Big sigh....

Just as the thread says. Everything runs fine when in debugger, but I get a 'not initialized' error when in release when it comes to a list : "object should first be initialized(List).".

Like I said everything smooth in Debug.

What am I doing wrong.

Thanks,
 

koffie

Member
Licensed User
Longtime User
Without seeing what exactly you have done, how could you expect getting any concrete help.
Thought there were 1 or 2 general common errors when it comes to populating lists.
B4X:
Sub Activity_Create(FirstTime As Boolean)

 Activity.LoadLayout("Layout1")
  Dim GD As GradientDrawable
  GD.Initialize("TR_BL", Array As Int(Colors.Blue, Colors.LightGray))
  Activity.Background = GD
 
   
  ImageView1.Initialize("test")
  ImageView1.Color = Colors.ARGB(25,0,0,0)
   

  Panel1.visible=False
  ListView1.SingleLineLayout.ItemHeight = 50dip
  ListView1.SingleLineLayout.Label.TextSize = 20
  ListView1.SingleLineLayout.Label.TextColor = Colors.White
  ListView1.SingleLineLayout.Label.Gravity = Gravity.LEFT
  ListView1.FastScrollEnabled = True
  filelist.Initialize
  path1="/storage/extSdCard"
ListFolderContent(path1)
End Sub


Sub ListFolderContent(folder As String) 'As String
Dim n As Int

  filelist = File.ListFiles(path1)
  filelist.Sort(True)
  For n = 0 To filelist.Size-1
  file1 = filelist.Get(n)
   'Log ("file1:"&file1)
  ListView1.AddSingleLine(file1)
  Next
End Sub

Like I said...no problems in Debug.....error in Release....
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Where do you declare path1 and filelist ?
When you call the ListFolderContent routine you pass the variable path1 to the variable folder.
But in the routine you use path1 and not folder.
I suspect that in ListFolderContent filelist is either not known or empty.
From the help of ListFiles:
An uninitialized list will be returned if the folder is not accessible.

The degugger mode is more foregiving than the release mode.
 
Upvote 0

koffie

Member
Licensed User
Longtime User
Where do you declare path1 and filelist ?
When you call the ListFolderContent routine you pass the variable path1 to the variable folder.
But in the routine you use path1 and not folder.
I suspect that in ListFolderContent filelist is either not known or empty.
From the help of ListFiles:
An uninitialized list will be returned if the folder is not accessible.

The degugger mode is more foregiving than the release mode.
Yeah,
I saw your response in one of the forums. But....

some more tinkering:
B4X:
filelist = File.ListFiles("/storage/extSdCard") gives a VALID response in DEBUG BUT an invalid reponse in Release....
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Sub ListFolderContent(folder As String) 'As String
Dim n As Int

filelist =
File.ListFiles(path1)
In
B4X:
file.listfiles(folder)
you should use the given path instead of an variable which can be unknown to the sub.

I dont know whether it is the problem or not. Hard to say with your code-snippet
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
gives a VALID response in DEBUG BUT an invalid reponse in Release....
If you are using Kitkat or higher you probably dont have access to the ext sdcard.
On older Android versions you need to add the permission to write external storages.

Starting with android 5 (Lollipop) you can use this library to get the right path to the external SDCard
 
Upvote 0

koffie

Member
Licensed User
Longtime User
If you are using Kitkat or higher you probably dont have access to the ext sdcard.
On older Android versions you need to add the permission to write external storages.

Starting with android 5 (Lollipop) you can use this library to get the right path to the external SDCard

You guys are great.....

B4X:
AddPermission(android.permission.WRITE_MEDIA_STORAGE)
AddPermission(android.permission.WRITE_EXTERNAL_STORAGE)

did it....

Thanks,
 
Upvote 0
Top