I'm having a little problem. I made a very simple game of randomizing a range of numbers. I click a button and then a random number appears on the screen based on a manual range. EVERYTHING is working fine until the range is left empty (I have two "EditText" boxes to enter the range) and then I get this "java.lang.NumberFormatException" error. I only get the error if not entering any numbers as my ranges, if left empty.
This is my first app with Basic4Android, and although I find it very logical and awesome, it is hard to find specific examples and solutions...
Can someone please help? Can you provide the exact code to enter and explain it? Thank you so much in advance. Here is the code, the issue I think is in the "btnrandom_Click" section:
This is my first app with Basic4Android, and although I find it very logical and awesome, it is hard to find specific examples and solutions...
Can someone please help? Can you provide the exact code to enter and explain it? Thank you so much in advance. Here is the code, the issue I think is in the "btnrandom_Click" section:
B4X:
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim Timer1 As Timer
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim Start_Range, End_Range As EditText
Dim K As Int
Dim Label1 As Label
Dim btnrandom As Button
Dim Exit As Button
Dim stayawake As PhoneWakeState
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("gnnLayout01custom")
Timer1.Initialize ("Timer1",2000)
'==========================================================================
'The following is to change the background color on "EditText" fields:
'
Dim enabled1, disabled1 As ColorDrawable
enabled1.Initialize(Colors.Transparent, 10dip)
disabled1.Initialize(Colors.Transparent, 10dip)
Dim sld As StateListDrawable
sld.Initialize
sld.AddState(sld.State_Enabled, enabled1)
sld.AddState(sld.State_Disabled, disabled1)
Start_Range.Background = sld
End_Range.Background = sld
'
'Or use this other method, which uses a backgound image:
'
'Dim enabled2, disabled2 As BitmapDrawable
'enabled2.Initialize(LoadBitmap(File.DirAssets, "Copper_Brushed_01.jpg"))
'disabled2.Initialize(LoadBitmap(File.DirAssets, "Copper_Brushed_01.jpg"))
'
'Dim sld As StateListDrawable
'sld.Initialize
'sld.AddState(sld.State_Enabled, enabled2)
'sld.AddState(sld.State_Disabled, disabled2)
'Start_Range.Background = sld
'End_Range.Background = sld
'==========================================================================
End Sub
Sub Activity_Resume
'stayawake.KeepAlive (True) 'This will automatically keep the screen on as app is loaded
End Sub
Sub Activity_Pause (UserClosed As Boolean)
'stayawake.ReleaseKeepAlive 'This will automatically keep the screen off as app is closed
End Sub
Sub btnrandom_Click
Dim SR, ER As Float
SR = Start_Range.Text
ER = End_Range.Text
'If IsNumber(Start_Range.Text) = True Then
'If Start_Range.Text = True Then
' k = Rnd (SR, ER+1)
' Label1.Text = K
' Timer1.Enabled = True
'Else
' Msgbox("Enter Range", "Error")
'End If
'If IsNumber(End_Range.Text) = True Then
'If End_Range.Text = True Then
' k = Rnd (SR, ER+1)
' Label1.Text = K
' Timer1.Enabled = True
'Else
' Msgbox("Enter Range", "Error")
'End If
'If IsNumber(Start_Range.Text) = " " Then
'If Start_Range.Text < 0 Then
' Msgbox("Enter Range", "Error")
'Else
' k = Rnd (SR, ER+1)
' Label1.Text = K
' Timer1.Enabled = True
'End If
'
'If IsNumber(End_Range.Text) = " " Then
'If End_Range.Text < 0 Then
' Msgbox("Enter Range", "Error")
'Else
' k = Rnd (SR, ER+1)
' Label1.Text = K
' Timer1.Enabled = True
'End If
If Start_Range.Text > End_Range.Text Then
Msgbox("'Start Range' must be less than 'End Range'", "")
Else If Start_Range.Text = End_Range.Text Then
Msgbox("The RANGE must be at least one number appart!", "")
Else If Start_Range.Text = Null Then 'I am using Null to say empty or no value, is this right?
Msgbox("Enter the Start Range!", "")
Else If End_Range.Text = Null Then 'I am using Null to say empty or no value, is this right?
Msgbox("Enter the End Range!", "")
Else
k = Rnd (SR, ER+1)
Label1.Text = K
Timer1.Enabled = True
End If
End Sub
Sub Timer1_Tick
Label1.Text = ""
Timer1.Enabled = False
End Sub
Sub ScreenCheckBox1_CheckedChange(Checked As Boolean)
If Checked = True Then
stayawake.KeepAlive (True)
Else
stayawake.ReleaseKeepAlive
End If
End Sub
Sub Exit_Click
Activity.Finish
End Sub