Android Question Error on writing camera app

imak123

Member
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



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
 

imak123

Member
I try to run the Main in the CamerExClass example. However I meet the following error.

---- Error Message --
B4A Version: 11.00
Parsing code. (0.02s)
Java Version: 11
Building folders structure. (0.03s)
Compiling code. Error
Error compiling program.
Error description: Property: Width is readonly.
Error occurred on line: 248
cs.Width = r.GetField("width")
Word: =

------------------------------------------------


Would you give me some advice ?



Thanks
MAk
 

Attachments

  • error.jpg
    430.5 KB · Views: 104
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…