[HELP] button

crisjue

New Member
guys help me, everytime i click the button this error always show

" an error has occurred in sub:main_solvebutton_click(javaline:428)
java.lang.Number format exemption:invalid double: "" "


help me guys...
 

lagore

Active Member
Licensed User
Longtime User
Without seeing your code it is very hard to tell, but Number format requires a 'double' I suspect you are passing something other then a double to it and this is causing the exception.
 
Upvote 0

crisjue

New Member
here is my codes.... help...

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

Dim texta As Float
Dim textb As Float
Dim textc As Float

Dim equation1 As Float
Dim equation2 As Float
Dim equation3 As Float

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 clearbutton As Button
Dim EditTexta As EditText
Dim EditTextb As EditText
Dim EditTextc As EditText
Dim Label1 As Label
Dim Label2 As Label
Dim Label3 As Label
Dim Label4 As Label
Dim Label5 As Label
Dim Label6 As Label
Dim lblroot1 As Label
Dim lblroot2 As Label
Dim quitbutton As Button
Dim solvebutton As Button

Dim statemanager As Int

End Sub

Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")

Activity.LoadLayout ("main")

If FirstTime = True Then
ToastMessageShow ("welcome!",False)
End If




EditTexta.InputType = EditTexta.INPUT_TYPE_DECIMAL_NUMBERS
EditTextb.InputType = EditTextb.INPUT_TYPE_DECIMAL_NUMBERS
EditTextc.InputType = EditTextc.INPUT_TYPE_DECIMAL_NUMBERS

End Sub

Sub Activity_Resume



End Sub

Sub Activity_Pause (UserClosed As Boolean)


End Sub



Sub quitbutton_Click

Dim quit As Int
quit = Msgbox2("Are you sure you want to quit?","","YES","","NO",Null)
If quit = DialogResponse.POSITIVE Then
ToastMessageShow("Goodbye!",False)
Activity.finish
End If

End Sub

Sub clearbutton_Click

EditTexta.Text = ""
EditTextb.Text = ""
EditTextc.Text = ""
lblroot1.Text = ""
lblroot2.Text = ""

End Sub
Sub solvebutton_Click

texta = EditTexta.Text
textb = EditTextb.Text
textc = EditTextc.Text

' -- computations -- '

equation1 = Power(textb,2) - (4 * (texta * textc)) 'b2-4ac

If equation1 > 0 Then
ToastMessageShow("There are 2 Roots!",False)
equation2 = (-textb - Sqrt(equation1)) / (2 * texta)
equation3 = (-textb + Sqrt(equation1)) / (2 * texta)
lblroot1.Text = equation2
lblroot2.Text = equation3

Else If equation1 = 0 Then
ToastMessageShow("There is 1 Root!",False)
equation3 = -textb / (2 * texta)
lblroot1.Text = equation3
lblroot2.text = ""

Else If equation1 < 0 Then
ToastMessageShow("There is an imaginary number in the equation!",False)
lblroot1.Text = ""
lblroot2.Text = ""
End If

End Sub



Sub EditTexta_TextChanged (Old As String, New As String)

Dim aline As String
aline = EditTexta.Text

If aline.Length > 4 Then
EditTexta.Text = aline.SubString2(0,4)
EditTexta.SelectionStart = 4
ToastMessageShow("3 character limit",False)
End If

End Sub

Sub EditTextb_TextChanged (Old As String, New As String)

Dim bline As String
bline = EditTextb.Text

If bline.Length > 4 Then
EditTextb.Text = bline.SubString2(0,4)
EditTextb.SelectionStart = 4
ToastMessageShow("3 character limit",False)
End If

End Sub

Sub EditTextc_TextChanged (Old As String, New As String)

Dim cline As String
cline = EditTextc.Text

If cline.Length > 4 Then
EditTextc.Text = cline.SubString2(0,4)
EditTextc.SelectionStart = 4
ToastMessageShow("3 character limit",False)
End If

End Sub
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Declare these as strings instead of float:

B4X:
Dim texta As String
Dim textb As String
Dim textc As String

Also to trap the error add this to your code:
B4X:
Sub solvebutton_Click

texta = EditTexta.Text 
textb = EditTextb.Text 
textc = EditTextc.Text 

'BELOW IS THE NEW CODE:
If IsNumber(texta)=False OR IsNumber(textb)=False OR IsNumber(textc)=False Then
   Msgbox("a, b and c must be numeric","Warning")
   Return
End If
 
Upvote 0

crisjue

New Member
Yes! it works. thanks thanks.


another problem is when i change my orientation, all the input values are deleted.. please help me..
 
Upvote 0
Top