java.lang.NumberFormatException:

luisftv

Member
Licensed User
Longtime User
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 soluctions...

Can someone please help? Can you provide the exact code to enter? Thank you so much in advance. Here is the code, the issue I think is in the "btnrandom_Click" section:

Sub Process_Globals
Dim Timer1 As Timer
End Sub

Sub Globals
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)

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
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub btnrandom_Click
Dim SR, ER As Float
SR = Start_Range.Text
ER = End_Range.Text

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 If SR AND ER = Null Then
Msgbox("Enter Range","")
Else
k = Rnd (SR, ER+1)
Label1.Text = K
Timer1.Enabled = True
End If
End Sub

Sub Exit_Click
Activity.Finish
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
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…