Hello everyone can someone help me?
I have a database that contains over 2000 words.
I take a word at random I count the number of letters and
I create as many labels as there are letters in the word.
But it does not work.
i have this error message : java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
Here is the code
Thank you for your help
I have a database that contains over 2000 words.
I take a word at random I count the number of letters and
I create as many labels as there are letters in the word.
But it does not work.
i have this error message : java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
Here is the code
b4a:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Private xui As XUI
Private SQL1 As SQL
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
Private Label1 As Label
Private myMots As String
Private pnlMots As Panel
Private lblName() As B4XView
End Sub
Sub Activity_Create(FirstTime As Boolean)
If Not(File.Exists(File.DirInternal, "db_mots.db3")) Then
File.Copy(File.DirAssets, "db_mots.db3", File.DirInternal, "db_mots.db3")
End If
SQL1.Initialize(File.DirInternal, "db_mots.db3", True)
Activity.LoadLayout("Layout")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Button1_Click
random_word
End Sub
Sub random_word
pnlMots.RemoveAllViews
'select a word in the database
Dim c As Cursor
Dim r As Int
c = SQL1.ExecQuery("SELECT * FROM mots ORDER BY RANDOM()" )
c.Position = 0
r = c.RowCount
For Row = 0 To r - 1
c.Position = Row
myMots = c.GetString("mots")
Next
c.Close
Label1.Text = "view test : " &myMots.Length &" : "&myMots
'creates (x) labels based on the number of letters in the word
Dim dist As Int=0
For i = 0 To myMots.Length-1
lblName(i).Tag = i
lblName(i).Text = myMots.CharAt(i)
lblName(i).TextSize = 24
lblName(i).TextColor = Colors.Black
pnlMots.AddView(lblName(i), dist, 30, 40, 40)
dist = dist + 40
Next
End Sub
Thank you for your help