I try to write a simple camera app, however I meet the following error :
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.hardware.Camera.takePicture(android.hardware.Camera$ShutterCallback, android.hardware.Camera$PictureCallback, android.hardware.Camera$PictureCallback)' on a null object reference...
I have add permission in manfiest:
AddPermission(android.permission.CAMERA)
Would you give me some advise ?
Thanks
Mak
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.hardware.Camera.takePicture(android.hardware.Camera$ShutterCallback, android.hardware.Camera$PictureCallback, android.hardware.Camera$PictureCallback)' on a null object reference...
I have add permission in manfiest:
AddPermission(android.permission.CAMERA)
Would you give me some advise ?
Thanks
Mak
B4X:
#Region Project Attributes
#ApplicationLabel: Ch13Camera
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
End Sub
Sub Globals
Dim cam As Camera
Dim pnl As Panel
Private btEnd As Button
Private btn1 As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("main")
End Sub
Sub camera_Ready (Success As Boolean)
If Success Then
cam.StartPreview
Else
ToastMessageShow("無法開啟相機 !", True)
End If
End Sub
Sub camera_PictureTaken (Data() As Byte)
cam.StartPreview
Dim out As OutputStream
out = File.OpenOutput(File.DirRootExternal, "pic1.jpg", False)
out.WriteBytes(Data, 0, Data.Length)
out.Close
ToastMessageShow("照片存放位置為 : " & _
File.Combine(File.DirRootExternal, "pic1.jpg"), True)
End Sub
Sub btn1_Click
'iv.Enabled = False
Log("iv Click")
cam.TakePicture
End Sub
Sub btEnd_Click
cam.StopPreview
cam.Release
Activity.Finish
End Sub
Sub Activity_Resume
'iv.Enabled = False
cam.Initialize(pnl, "camera")
End Sub
Sub Activity_Pause (UserClosed As Boolean)
cam.Release
End Sub