I am trying to create, either, an two-dimensional string array, or a List of arrays.
I would like to load in 4 different sentences for 365 different days from a text file, then access them like:
Day(235,1) would equal the first sentence of the 235th day... Day(365, 3) would equal the 3rd sentence of the 365th day. (Day(365, 0) might equal the total number of sentences for that day... because maybe in the future they might be more than 4 sentences per day).
I have tried both methods.
I have tried declaring a list in the Global area, then populating it in a Sub.
I have tried declaring the list in the Global area and populating it in the global area.
I have tried declaring a two-dimensional array in the Global area and populating it in Sub.
I have even succeeded, if one were to count using Log(Day(365,3))
However, whenever I try an actually use that string or return it as a value, or even print it in a StringFunction message Box... it always gives me an error of java.lang.NullPointerException
I'm figuring that the problem has to do with the original definition being just a reference pointer to a string which isn't really there later.
What is the proper way of declaring (either a list which will be a list of string arrays) or a two-dimensional string array so I can fill them in either at the beginning and then access them later, or fill them in from a Sub later without getting that annoying "NullPointrException" error?
365 x 4 real strings need to be created, globally.
Then, in some fashion, either a List of Array pointers has to point to those strings.
And, after they have been declared... how does one access them?
When I was doing experiments using a list of arrays, I seemed to be setting-up the list of arrays properly... but I could then never access the arrays, and thus those string array items properly.
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim ListOfArrays As List
Dim sf As StringFunctions
Dim TimingArray(5) As String
End Sub
Sub Activity_Create(FirstTime AsBoolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("main")
Dim z As Short
Dim sf As StringFunctions
ListOfArrays.Initialize ' (I've also tried putting this in the Globals area)
For z = 0 To 365
Dim TimingArray(5) As String
TimingArray(0) = "4"
TimingArray(1) = "A" & NumToStr(z)
TimingArray(2) = "B" & NumToStr(z)
TimingArray(3) = "This is a test of the emergency broadcast system" & NumToStr(z)
TimingArray(4) = "D" & NumToStr(z)
ListOfArrays.Add(TimingArray)
Next
' Creates a string pointer called GetArray?
Dim GetArray() AsString
' Points the GetArray string pointer to the 25th Array in the ListOfArrays List and accesses the 25th
GetArray = ListOfArrays.Get(25)
Log(GetArray(3)) ' And, it shows "This is a test of the emergency broadcast system25"
TheString = GetArray(3) ' Doesn't cause problem to assign it. Must be a string pointer.
sf.MB(TheString) 'Gives null pointer error any time I try actually using that value
End Sub
The same exact thing happened when I tried to create a two-dimensional array.
What's the right way of doing it?
I would like to load in 4 different sentences for 365 different days from a text file, then access them like:
Day(235,1) would equal the first sentence of the 235th day... Day(365, 3) would equal the 3rd sentence of the 365th day. (Day(365, 0) might equal the total number of sentences for that day... because maybe in the future they might be more than 4 sentences per day).
I have tried both methods.
I have tried declaring a list in the Global area, then populating it in a Sub.
I have tried declaring the list in the Global area and populating it in the global area.
I have tried declaring a two-dimensional array in the Global area and populating it in Sub.
I have even succeeded, if one were to count using Log(Day(365,3))
However, whenever I try an actually use that string or return it as a value, or even print it in a StringFunction message Box... it always gives me an error of java.lang.NullPointerException
I'm figuring that the problem has to do with the original definition being just a reference pointer to a string which isn't really there later.
What is the proper way of declaring (either a list which will be a list of string arrays) or a two-dimensional string array so I can fill them in either at the beginning and then access them later, or fill them in from a Sub later without getting that annoying "NullPointrException" error?
365 x 4 real strings need to be created, globally.
Then, in some fashion, either a List of Array pointers has to point to those strings.
And, after they have been declared... how does one access them?
When I was doing experiments using a list of arrays, I seemed to be setting-up the list of arrays properly... but I could then never access the arrays, and thus those string array items properly.
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim ListOfArrays As List
Dim sf As StringFunctions
Dim TimingArray(5) As String
End Sub
Sub Activity_Create(FirstTime AsBoolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("main")
Dim z As Short
Dim sf As StringFunctions
ListOfArrays.Initialize ' (I've also tried putting this in the Globals area)
For z = 0 To 365
Dim TimingArray(5) As String
TimingArray(0) = "4"
TimingArray(1) = "A" & NumToStr(z)
TimingArray(2) = "B" & NumToStr(z)
TimingArray(3) = "This is a test of the emergency broadcast system" & NumToStr(z)
TimingArray(4) = "D" & NumToStr(z)
ListOfArrays.Add(TimingArray)
Next
' Creates a string pointer called GetArray?
Dim GetArray() AsString
' Points the GetArray string pointer to the 25th Array in the ListOfArrays List and accesses the 25th
GetArray = ListOfArrays.Get(25)
Log(GetArray(3)) ' And, it shows "This is a test of the emergency broadcast system25"
TheString = GetArray(3) ' Doesn't cause problem to assign it. Must be a string pointer.
sf.MB(TheString) 'Gives null pointer error any time I try actually using that value
End Sub
The same exact thing happened when I tried to create a two-dimensional array.
What's the right way of doing it?