Android Question Take picture after msgbox2 got runtime exception error

donnyy

Member
Licensed User
Longtime User
i have created a screen with a front camera preview and a keypad where user can enter his code, after user entered his code and press the ENTER button, it will pop up and ask the user to confirm. What i wanted to do is, in the ENTER button click event, i want the app to take a picture after the user press Yes in Msgbox2. However, i keep getting a 'RuntimeException:Cannot parse: -1 as boolean' error after i press Yes. It works fine if i don't have the message box. Any help would be appreciated. Thanks
 

JonPM

Well-Known Member
Licensed User
Longtime User
We'll need to see your code, or a small sample project, in order to help you.
 
Upvote 0

donnyy

Member
Licensed User
Longtime User
Here is my code, i use the camera example to modify it.

#Region Module Attributes
#FullScreen: False
#IncludeTitle: False
#ApplicationLabel: ClockIn
#VersionCode: 1
#VersionName:
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region

'Activity module
Sub Process_Globals
Private frontCamera As Boolean = True
Dim Timer1 As Timer
Dim SQLdb As SQL
End Sub

Sub Globals
Private Panel1 As Panel
Private Panel2 As Panel
Private Panel3 As Panel
Private Panel4 As Panel
Private camEx As CameraExClass
Dim curDate As Label
Private Btn0 As Button
Private Btn1 As Button
Private Btn2 As Button
Private Btn3 As Button
Private Btn4 As Button
Private Btn5 As Button
Private Btn6 As Button
Private Btn7 As Button
Private Btn8 As Button
Private Btn9 As Button
Private BtnEnter As Button
Private btnReset As Button
Private codeEnter As String
Private Showcode As EditText
Private Cursor1 As Cursor
Private clockinDir As String
clockinDir = File.Combine(File.DirDefaultExternal,"/clockin/data")
Private clockinimageDir As String
clockinimageDir = File.Combine(File.DirDefaultExternal,"/clockin/data/images")
End Sub

Sub Activity_Create(FirstTime As Boolean)
ToastMessageShow(File.DirDefaultExternal,True)
If (File.IsDirectory(File.DirDefaultExternal,"/clockin/data/") = False) Then
File.MakeDir(File.DirDefaultExternal,"/clockin/data")
File.MakeDir(File.DirDefaultExternal,"/clockin/data/images")

End If

If FirstTime Then
' SQLdb.Initialize(File.DirRootExternal, "clockin.db",True)
SQLdb.Initialize(clockinDir, "clockin.db",True)
End If

CreateTables
FillData
Activity.LoadLayout("1")
Timer1.Initialize("Timer1", 1000)
Timer1.Enabled = True
codeEnter = ""

End Sub

Sub Activity_Resume
InitializeCamera
Timer1.Enabled = True
codeEnter = ""
End Sub

Private Sub InitializeCamera
camEx.Initialize(Panel1, frontCamera, Me, "Camera1")
frontCamera = camEx.Front
End Sub

Sub Activity_Pause (UserClosed As Boolean)
camEx.Release
Timer1.Enabled = False
End Sub

Sub Timer1_tick
ShowTime
End Sub

Sub ShowTime
Dim now, i As Long
' Dim t As String
' DateTime.DateFormat = "h:mm a"
now = DateTime.Now
' t = DateTime.Time(now) ' e.g.: "14:25:10"
' t = t.SubString2(0, 5) ' e.g.: "14:25"
' i = t.SubString2(0, 2) ' e.g.: "14"
' If i >= 13 Then
' i = i - 12 ' Change from 24-hour time to 12-hour time
' t = i & t.SubString(2) ' e.g.: "2" & ":25"
' End If
curDate.Text = DateTime.Date(now) & " " & DateTime.Time(now)
End Sub

Sub Camera1_Ready (Success As Boolean)
If Success Then
camEx.SetJpegQuality(90)
camEx.CommitParameters
camEx.StartPreview
Log(camEx.GetPreviewSize)
Else
ToastMessageShow("Cannot open camera.", True)
End If
End Sub

Sub btnTakePicture_Click
camEx.TakePicture
End Sub

Sub btnFocus_Click
camEx.FocusAndTakePicture
End Sub

Sub Camera1_PictureTaken (Data() As Byte)
Dim filename As String = "1.jpg"
Dim dir As String = clockinimageDir 'File.DirInternal

camEx.SavePictureToFile(Data, dir, filename)
camEx.StartPreview 'restart preview

'send a broadcast intent to the media scanner to force it to scan the saved file.
Dim Phone As Phone
Dim i As Intent
i.Initialize("android.intent.action.MEDIA_SCANNER_SCAN_FILE", _
"file://" & File.Combine(dir, filename))
Phone.SendBroadcastIntent(i)
ToastMessageShow("Picture saved." & CRLF & "File size: " & File.Size(dir, filename), True)
End Sub

Sub CreateTables
SQLdb.ExecNonQuery("DROP TABLE IF EXISTS usertbl")
SQLdb.ExecNonQuery("DROP TABLE IF EXISTS clocktbl")
SQLdb.ExecNonQuery("CREATE TABLE usertbl (id INTEGER, name TEXT, usercode INTEGER)")
SQLdb.ExecNonQuery("CREATE TABLE clocktbl (id INTEGER, clkdate TEXT, clktime TEXT, usercode INTEGER, clkimage BLOB)")
End Sub

Sub FillData
SQLdb.ExecNonquery("INSERT INTO usertbl (id, name, usercode) values ('','Donny Yu','1220')")
End Sub

Sub Btn0_Click
codeEnter = codeEnter & "0"
Showcode.Text = codeEnter
End Sub
Sub Btn1_Click
codeEnter = codeEnter & "1"
Showcode.Text = codeEnter
End Sub
Sub Btn2_Click
codeEnter = codeEnter & "2"
Showcode.Text = codeEnter
End Sub
Sub Btn3_Click
codeEnter = codeEnter & "3"
Showcode.Text = codeEnter
End Sub
Sub Btn4_Click
codeEnter = codeEnter & "4"
Showcode.Text = codeEnter
End Sub
Sub Btn5_Click
codeEnter = codeEnter & "5"
Showcode.Text = codeEnter
End Sub
Sub Btn6_Click
codeEnter = codeEnter & "6"
Showcode.Text = codeEnter
End Sub
Sub Btn7_Click
codeEnter = codeEnter & "7"
Showcode.Text = codeEnter
End Sub
Sub Btn8_Click
codeEnter = codeEnter & "8"
Showcode.Text = codeEnter
End Sub
Sub Btn9_Click
codeEnter = codeEnter & "9"
Showcode.Text = codeEnter
End Sub
Sub BtnReset_Click
codeEnter = ""
Showcode.Text = codeEnter
End Sub

Sub BtnEnter_Click

Dim username, sqlstr As String
Dim Count As Int
Dim codeOK, confirmOK As Boolean

Count = SQLdb.ExecQuerySingleResult("SELECT count(*) FROM usertbl WHERE usercode = '" & Showcode.Text & "'")
If (Count <= 0) Then
Msgbox("Invalid User Code","Error")
Showcode.Text=""
codeEnter = ""
Else
Cursor1 = SQLdb.ExecQuery("SELECT * From usertbl WHERE usercode = '" & Showcode.TEXT & "'")
For i = 0 To Cursor1.RowCount - 1
Cursor1.Position = i
username = Cursor1.GetString("name")
Next
Cursor1.Close

confirmOK = Msgbox2(username,"Please Confirm","Yes","","No",Null)
' If (DialogResponse.NEGATIVE) Then
' File.Delete(clockinimageDir,"1.jpg")
' Showcode.Text=""
' codeEnter = ""
' End If
If (confirmOK) Then
' ' sqlstr = "INSERT into clocktbl (id, clkdate, clktime, usercode, clkimage) VALUES ('',"
Showcode.Text=""
codeEnter = ""
codeOK = True
camEx.TakePicture
Else
File.Delete(clockinimageDir,"1.jpg")
Showcode.Text=""
codeEnter = ""
End If
End If

End Sub

Thank you.
 
Upvote 0

JonPM

Well-Known Member
Licensed User
Longtime User
Couple things: Please use Code tags whenever posting code in the forums. Also, you should only post the relevant code rather than all of it.

Here is your problem:
B4X:
If (confirmOK) Then

Msgbox2 returns an Int, not a boolean. Your code should instead be:
B4X:
If (confirmOK = DialogResponse.Positive) Then
 
Upvote 0

donnyy

Member
Licensed User
Longtime User
Thank you. I will remember to just post the relevant code next time. You have solved my problem. Thanks again.
 
Last edited:
Upvote 0
Top