Android Question Large lists

scarr

Member
Licensed User
Longtime User
Hi All,

I have a program that I wrote a couple of years ago, it compiled and worked OK at the time, the other day I wanted to make a change, so I loaded up the code and compiled it, it failed! saying the code was too large. There are 4143 integers in each list

So after playing around I found that removing two large lists in Process_Globals allowed it to compile, so here are my questions.

1) has something changed in that stops you using large lists
2) Any idea how to fix this.

Thanks

Steve

P.S. In the altered code (one without the two large lists) I create another activity with just one of the large lists and nothing else to see if I could separate them out, this failed to compile.
 

DonManfred

Expert
Licensed User
Longtime User
saying the code was too large. There are 4143 integers in each list
are you using 4143 codelines to fill the list? Why not loading the List directly?
B4X:
Dim List1 As List
List1 = File.ReadList(File.DirDefaultExternal, "1.txt") ' List with 50000 Lines...
For i = 0 to List1.Size - 1
    Log(List1.Get(i))
Next
5 Lines of code.

How did you structure your code?
 
Upvote 0

scarr

Member
Licensed User
Longtime User
Extra Info:

I was creating the list this way as I was trying to avoid a separate file with the INT's in them

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

    Dim List3 As List

    List3.Initialize

List3.AddAll(Array As Int(475,275,700,675,625,375,700,850,50,325,675,525,275,575,250,725, _
    875,200,875,475,875,25,100,700,50,350,850,375,150,575,375,300, _
    200,525,425,250,350,825,550,100,625,750,500,400,450,425,375,50, _
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
To be honest; i just copied the example-code the IDE Onlinehelp suggests for File.ReadList :) ....
Will be fixed. File.DirDefaultExternal should not be used anymore. It was replaced with RuntimePermissions.GetSafeDirDefaultExternal.

I was creating the list this way as I was trying to avoid a separate file with the INT's in them
There are several mistakes here:
1. It is better to put them in a file and load them at runtime. It is a mistake to put data inside the code.
2. You shouldn't initialize or call AddAll in Process_Globals.
3. Unless you plan to modify the list in the future then it is better to initialize it like this:
B4X:
Private List3 As List = Array (475, 275, ...)
 
Upvote 0

scarr

Member
Licensed User
Longtime User
Will be fixed. File.DirDefaultExternal should not be used anymore. It was replaced with RuntimePermissions.GetSafeDirDefaultExternal.


There are several mistakes here:
1. It is better to put them in a file and load them at runtime. It is a mistake to put data inside the code.
2. You shouldn't initialize or call AddAll in Process_Globals.
3. Unless you plan to modify the list in the future then it is better to initialize it like this:
B4X:
Private List3 As List = Array (475, 275, ...)

Hi Erel, Where would you put your example? also Erel are you saying it is possible to have a large list within the code?

B4X:
Private List3 As List = Array (475, 275, ...)
 
Last edited:
Upvote 0

scarr

Member
Licensed User
Longtime User
No. This is just the way to initialize a List effectively. He mentioned that it is a mistake to put data in Code. This has not changed.

Thanks Don, the reason I put it in the code is I don't want the user to see the list or access it. any suggestions? also any good simple examples of using external files for lists?

Thanks Steve
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The user will not see the internal file.

You can create a text file with this content:
475
275
...

And load it as suggested above:
B4X:
List3 = File.ReadList(File.DirAssets, "data.txt")
Note that each element will be a string. In most cases it doesn't matter however if it does matter then you can do something like this:
B4X:
List3.Initialize
For Each s As String In File.ReadList(File.DirAssets, "data.txt")
 Dim n As Int = s
 List3.Add(n)
Next

Don't do it in Process_Globals. You should do it in Activity_Create when FirstTime is true (or better in the starter service).
 
Upvote 0

scarr

Member
Licensed User
Longtime User
The user will not see the internal file.

You can create a text file with this content:
475
275
...

And load it as suggested above:
B4X:
List3 = File.ReadList(File.DirAssets, "data.txt")
Note that each element will be a string. In most cases it doesn't matter however if it does matter then you can do something like this:
B4X:
List3.Initialize
For Each s As String In File.ReadList(File.DirAssets, "data.txt")
 Dim n As Int = s
 List3.Add(n)
Next

Don't do it in Process_Globals. You should do it in Activity_Create when FirstTime is true (or better in the starter service).


OK, so I will use an external file but firstly I have not used B4A for about two years so totally rusty (not that I was well oiled before :)) so I have a few newbie questions.


1) Can the list (data.txt) be created within B4A so it installs as part of the application or is it created in a simple text editor and I place it somewhere?
2) if I create and place it, where do I place it on the device?


Thanks for everyone's patience and help

Steve
 
Upvote 0

scarr

Member
Licensed User
Longtime User
Well that was easy :)

This is what a forum / software community should be, OK I'm no coding guru anymore, I used to love coding and was into assembly and C and all the other ones at the time, now my life occasionally meets code but I'm a lot older and have not got the time to understand 80% of modern IDE's / development languages or platforms :rolleyes: but with a community like this and the help it provides, especially Erel you personify the word "community" thanks for everything, I am sure I will be back in the future to make you all go o_O:rolleyes: but then help out as you do. thanks for helping an old man :)

Steve
 
Upvote 0
Top