Android Question ERROR Object should first be initialized (ImageView).

Matteo Granatiero

Active Member
Licensed User
ERROR on Activity.LoadLayout("cum")
B4X:
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
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim camera As AdvancedCamera
    Dim Panel1 As Panel

    Dim ImageView2 As ImageView
    'Dim ImageView6 As ImageView
    Dim close As ImageView

    Dim img4 As ImageView
    Dim PanelImage As Panel

    Dim PanelFrame As Panel
    Dim finale As ImageView

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("cum")

    If File.Exists(File.DirRootExternal,"Simulatore Camera") Then
        img4.Bitmap=LoadBitmap(File.DirRootExternal,"Simulatore Camera/sagoma.png")
        img4.Visible=True
    Else
        File.MakeDir(File.DirRootExternal, "Simulatore Camera")
        img4.Bitmap=LoadBitmap(File.DirRootExternal,"Simulatore Camera/sagoma.png")
        img4.Visible=True
    End If
End Sub

Sub Activity_Resume
    camera.Initialize(Panel1, "camera")
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    Activity.Finish
End Sub

Sub camera_Ready (Success As Boolean)
    If Success Then
        camera.StartPreview
     
    Else
        ToastMessageShow("Cannot open camera.", True)
    End If
End Sub
Sub camera_PictureTaken (Data() As Byte)
   
   
    camera.StartPreview
   
    'Dim c As Char = Chr(Rnd(33, 127))   'nome casuale
   
   
    close.Visible=True
       
    Dim out As OutputStream
    out = File.OpenOutput(File.DirRootExternal, "Simulatore Camera"  & "foto.jpg", False)
    out.WriteBytes(Data, 0, Data.Length)
    out.Close
    Panel1.Visible=False
       
       
    PanelImage.Visible=True
    PanelImage.SetBackgroundImage(LoadBitmap(File.DirRootExternal, "Simulatore Camera"  & "foto.jpg"))
    PanelFrame.Visible=True
    PanelFrame.SetBackgroundImage(LoadBitmap(File.DirRootExternal,"Simulatore Camera/sagoma2.png"))
       
    Dim BView As B4XView = PanelImage
    Dim l As Int = PanelImage.Left
    Dim T As Int = PanelImage.Top
    finale.SetBackgroundImage(BView.Snapshot)
    PanelImage.SetLayout(l,T,PanelImage.Width,PanelImage.Height)
    finale.Visible=True
    ImageView2.visible= False
End Sub

Sub close_Click
    camera.StartPreview
    img4.Visible=True
   
   
    close.Visible=False
    PanelImage.Visible=False
    Panel1.Visible=True
    ImageView2.Visible=True
    File.Delete(File.DirRootExternal, "Simulatore Camera"  & "foto.jpg")
    PanelImage.Visible=False
    PanelFrame.Visible=False
    finale.Visible=False
End Sub

Sub ImageView2_Click
    camera.TakePicture
End Sub
 

Star-Dust

Expert
Licensed User
Longtime User
You must indicate in which row the error is reported.

I still find one thing strange. You check if there is a folder that should contain a picture of the camera. If it does not find it, it creates the folder, and then loads the image, but the newly created folder should be empty.
What do you want to load if you do not put anything in before?

B4X:
If File.Exists(File.DirRootExternal,"Simulatore Camera") Then
        img4.Bitmap=LoadBitmap(File.DirRootExternal,"Simulatore Camera/sagoma.png")
        img4.Visible=True
    Else
        File.MakeDir(File.DirRootExternal, "Simulatore Camera")
        ' ?????
        ' file.copy(File.DirRootExternal, "Simulatore Camera",file.dirAssest,"sagoma.png")
        img4.Bitmap=LoadBitmap(File.DirRootExternal,"Simulatore Camera/sagoma.png")
        img4.Visible=True
    End If
 
Upvote 0

Matteo Granatiero

Active Member
Licensed User
You must indicate in which row the error is reported.

I still find one thing strange. You check if there is a folder that should contain a picture of the camera. If it does not find it, it creates the folder, and then loads the image, but the newly created folder should be empty.
What do you want to load if you do not put anything in before?

B4X:
If File.Exists(File.DirRootExternal,"Simulatore Camera") Then
        img4.Bitmap=LoadBitmap(File.DirRootExternal,"Simulatore Camera/sagoma.png")
        img4.Visible=True
    Else
        File.MakeDir(File.DirRootExternal, "Simulatore Camera")
        ' ?????
        ' file.copy(File.DirRootExternal, "Simulatore Camera",file.dirAssest,"sagoma.png")
        img4.Bitmap=LoadBitmap(File.DirRootExternal,"Simulatore Camera/sagoma.png")
        img4.Visible=True
    End If
the images and the folder already exist.
The error is at the "Activity.Load ..." line
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
It is strange that you give this error in the Layout. Try to attach the BAL file to the check
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I did not find any errors.
Maybe some variable or Class has the same name as a view in the Layout?

Post a small project that presents this problem so we can check it
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
The problem is generated by ImageView6.

Now I try to understand why
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Perhaps in ImageView6 there was an image that you took away. In the image field, I deleted the old value.
You can also try to delete and recreate ImageView6.

I corrected the example you sent me, it works for me now. try it
 

Attachments

  • matteo.zip
    48.9 KB · Views: 227
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
I emptied the FileImage field of ImageView 6. There was an old value, an image that could not load
upload_2018-8-23_19-22-3.png
 
Upvote 0
Top