Android Question Load pictures into ImageView on the designer

parijs

Active Member
Licensed User
Longtime User
Hi i try to load pictures into ImageView on the designer "ImageView1, ImageView2" but the are empty.


B4X:
Sub paneel1
   
    For i = 1 To 2
       
    Dim ImageView1, ImageView2 , ImageView3 As ImageView   
    Dim ImageViews() As ImageView
    ImageViews = Array As ImageView(ImageView1, ImageView2, ImageView3)
    ImageViews(i).Initialize("")   
   
    SQL.Initialize(File.DirRootExternal, "Perel/pere.db", False)
    cur = SQL.ExecQuery2("SELECT * FROM lachaise WHERE id =  ?", Array As String(i))   
    cur.Position = 0
   
    Dim Buffer() As Byte 'declare an empty byte array
    Buffer = cur.GetBlob("pic")
   
    Dim InputStream1 As InputStream
    InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
    Dim Bitmap11 As Bitmap
    Bitmap11.Initialize2(InputStream1)
    ImageViews(i).SetBackgroundImage(Bitmap11)
   
    Next
    InputStream1.Close

End Sub
 

parijs

Active Member
Licensed User
Longtime User
Hi Erel,

In vp.Panels(1).LoadLayout("1") i have srollview "scvTest"
In "pers" i have 2 imageviews RA1 and RA2
And i have this error

B4X:
Error occurred on line: 79 (Main)
java.lang.RuntimeException: Object should first be initialized (ImageView).
Did you forget to call Activity.LoadLayout?

This is line 79 " RA(i).Bitmap = Bitmap11"


B4X:
    File.MakeDir(File.DirRootExternal,"Perel")
    File.Copy(File.DirAssets,"pere.db", File.DirRootExternal, "Perel/pere.db")
   
    Dim height As Int = CalculateHeight(True, True)
    vp.Initialize("vp", 4, 100%x, height)
    Activity.AddView(vp.AsView, 0, 0, 100%x, height)
    'load the pages layouts
    vp.Panels(0).LoadLayout("0")
    vp.Panels(1).LoadLayout("1")
    scvTest.Panel.LoadLayout("pers")
   
    Dim RA1, RA2 As ImageView  
    Dim RA(10) As ImageView

     RA = Array As ImageView(ImageView1, ImageView2, ImageView3)      
       
        For i = 1 To 2
      
    SQL.Initialize(File.DirRootExternal, "Perel/pere.db", False)
    cur = SQL.ExecQuery2("SELECT * FROM lachaise WHERE id =  ?", Array As String(i))  
    cur.Position = 0
  
    Dim Buffer() As Byte 'declare an empty byte array
    Buffer = cur.GetBlob("pic")
  
    Dim InputStream1 As InputStream
    InputStream1.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
    Dim Bitmap11 As Bitmap
    Bitmap11.Initialize2(InputStream1)
    RA(i).Bitmap = Bitmap11
  
    Next
    InputStream1.Close
   
    Panel2.Height = 3860dip
    scvTest.Panel.Height = Panel2.Height + 800
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…