Hi, I'm new to the forum and I'm a beginner. I'm trying to load an image from the smartphone gallery and then save it in the database and then upload it to a listview. But I keep getting errors !. At the fristtime I open the gallery of the smartphone I select an image and I return the message (Image Added) that makes me deduce that the rescue in the db has been successful. But when I restart the app it returns me this error: java.lang.NullPointerException: Attempt to get length of null array.
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
    If Success Then
 
      
Dim b() As Byte = ImageToBytes(xui.LoadBitmap(Dir,FileName))
      
s.ExecNonQuery("INSERT INTO Image (Picture) VALUES('" & b.Length & "')")
ToastMessageShow("Image Added",True)
    
Else
ToastMessageShow("No image selected", True)
End If
End Sub[[/CODE]
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
			
			
			
				B4X:
			
		
		
		Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("ImageHome")
    LoadSystem
    LoadListImage
   
End Sub
			
				B4X:
			
		
		
		Sub ImageViewAggImage_Click
    Dim Chooser As ContentChooser
    Chooser.Initialize("chooser")
    Chooser.Show("image/*", "Select an image")
   
End Sub
			
				B4X:
			
		
		
		Sub chooser_Result (Success As Boolean, Dir As String, FileName As String)Dim b() As Byte = ImageToBytes(xui.LoadBitmap(Dir,FileName))
s.ExecNonQuery("INSERT INTO Image (Picture) VALUES('" & b.Length & "')")
ToastMessageShow("Image Added",True)
Else
ToastMessageShow("No image selected", True)
End If
End Sub[[/CODE]
			
				B4X:
			
		
		
		Sub chooser_Result (Success As Boolean, Dir As String, FileName As String)
Sub LoadSystem
  
    Dim ruta As String
    If File.ExternalWritable Then
        ruta = File.DirInternal
    Else
        ruta = File.DirInternal
    End If
    If  File.Exists(File.DirInternal,"dbi.db")= False Then
        File.Copy(File.DirAssets,"dbi.db",File.DirInternal,"dbi.db")
    End If
    s.Initialize(ruta,"dbi.db",True)
    Log("dbi Inizializzato")
    init
End Sub
[CODE]Sub ImageToBytes( image As Bitmap) As Byte()
Dim out As OutputStream
out.InitializeToBytesArray(100)
image.WriteToStream(out,100,"JPG")
    Return out.ToBytesArray
End Sub
			
				B4X:
			
		
		
		Sub LoadListImage
 
    Dim Cursor1 As Cursor
    Dim Name As String
    Dim Buffer() As Byte
    Dim IpSt As InputStream
    Dim Bitmap1 As Bitmap
    Cursor1 = s.ExecQuery("SELECT  name,Picture FROM Image")
 
    For i = 0 To Cursor1.RowCount - 1
        Cursor1.Position = i
        Name =Cursor1.GetString("name")
        Buffer = Cursor1.GetBlob("Picture")
        IpSt.InitializeFromBytesArray(Buffer, 0, Buffer.Length)
        Bitmap1.Initialize2(IpSt)
        IpSt.Close
        ListViewImage.AddTwoLinesAndBitmap(Name,"",Bitmap1)
        Cursor1.Close
       
    Next
   
    SetDivider(ListViewImage, Colors.LightGray, 1dip)
 
End Sub 
				 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		