Jul 3 2012
06:00 Hours
I get this error only in version 4.1
Camera1_Ready - java.lang.NullPointerException
Here is the entire code of the activity
Ray Tesluk :sign0104:
06:00 Hours
I get this error only in version 4.1
Camera1_Ready - java.lang.NullPointerException
Here is the entire code of the activity
B4X:
'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
Dim Panel1 As Panel
Dim btnTakePicture As Button
Dim ButtonExit As Button
Dim LabelFileLocation As Label
Dim Camera1 As Camera
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("TakePic.bal")
Activity.Color = Colors.RGB(CodeModule.PanR,CodeModule.PanG,CodeModule.PanB)
LabelFileLocation.Text = "#"
LabelFileLocation.Color = Colors.RGB(CodeModule.LblR,CodeModule.LblG,CodeModule.LblB)
LabelFileLocation.TextColor = Colors.RGB(CodeModule.TxtR,CodeModule.TxtG,CodeModule.TxtB)
LabelFileLocation.TextSize = CodeModule.TCARndTextSize
If CodeModule.FancyFormatOnOff2 = True Then
LabelFileLocation.Background = CodeModule.GD(Colors.RGB(CodeModule.LblR,CodeModule.LblG,CodeModule.LblB),Colors.RGB(CodeModule.TxtR,CodeModule.TxtG,CodeModule.TxtB),CodeModule.TCVCurrentRndCornerValue,CodeModule.sPattern)
End If
End Sub
Sub Activity_Resume
btnTakePicture.Enabled = False
Camera1.Initialize(Panel1, "Camera1")
End Sub
Sub Activity_Pause (UserClosed As Boolean)
Camera1.Release
End Sub
Sub LabelFileLocation_Click
LabelFileLocation.Color = Colors.RGB(Rnd(0, 255), Rnd(0, 255), Rnd(0, 255))
LabelFileLocation.TextColor = Colors.RGB(Rnd(0, 255), Rnd(0, 255), Rnd(0, 255))
End Sub
Sub Camera1_Ready (Success As Boolean)
Try
If Success Then
Camera1.StartPreview
btnTakePicture.Enabled = True
Else
ToastMessageShow("Cannot open camera.", True)
End If
Catch
Msgbox(LastException.Message,"Camera1_Ready")
End Try
End Sub
Sub Camera1_PictureTaken (Data() As Byte)
Camera1.StartPreview
Dim Out As OutputStream
Dim CurrentDate, CurrentTime As Long, sDT As String
'Get No. of Ticks of Current Date CurrentDate Long = Primitive Variable
CurrentDate = DateTime.DateParse(DateTime.Date(DateTime.Now))
'Get No. of Ticks of Current Time CurrentTime Long = Primitive Variable
CurrentTime = DateTime.TimeParse(DateTime.Time(DateTime.Now))
sDT = ""
sDT = sDT & DateTime.GetYear(CurrentDate)
sDT = sDT & NumberFormat(DateTime.GetMonth(CurrentDate),2,0)
sDT = sDT & NumberFormat(DateTime.GetDayOfMonth(CurrentDate),2,0)
sDT = sDT & "_"
sDT = sDT & NumberFormat(DateTime.GetHour(CurrentTime),2,0)
sDT = sDT & NumberFormat(DateTime.GetMinute(CurrentTime),2,0)
sDT = sDT & NumberFormat(DateTime.GetSecond(CurrentTime),2,0)
sDT = sDT & ".jpg"
Try
If File.IsDirectory (File.DirRootExternal,CodeModule.sImgAudDir) = False Then
File.MakeDir(File.DirRootExternal,CodeModule.sImgAudDir)
End If
Out = File.OpenOutput(File.DirRootExternal & "/" & CodeModule.sImgAudDir, sDT, False)
Out.WriteBytes(Data, 0, Data.Length)
Out.Close
LabelFileLocation.Text = File.DirRootExternal & "/" & CodeModule.sImgAudDir & "/" & sDT
Catch
Msgbox(LastException.Message,"PictureTaken")
End Try
ToastMessageShow("Image saved: " & File.Combine(File.DirRootExternal & "/" & CodeModule.sImgAudDir, sDT), True)
btnTakePicture.Enabled = True
End Sub
Sub btnTakePicture_Click
btnTakePicture.Enabled = False
Camera1.TakePicture
End Sub
Sub ButtonExit_Click
Activity.Finish
StartActivity(Options)
End Sub
Ray Tesluk :sign0104: