Android Question error while downloading to phone gallery

Makumbi

Well-Known Member
Licensed User
this error comes
B4X:
iv.Bitmap = j.GetBitmap
i got this error on this code

B4X:
** Activity (main) Pause, UserClosed = false **
Sleep not resumed (context is paused): b4a.example3.customlistview$ResumableSub_PanelClickHandler
** Activity (downloadwork) Create, isFirst = true **
** Activity (downloadwork) Resume **
Error occurred on line: 257 (HttpJob)
java.lang.RuntimeException: Object should first be initialized (ImageView).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
    at anywheresoftware.b4a.objects.ImageViewWrapper.getGravity(ImageViewWrapper.java:44)
    at anywheresoftware.b4a.objects.ImageViewWrapper.SetBackgroundImageNew(ImageViewWrapper.java:86)
    at anywheresoftware.b4a.objects.ImageViewWrapper.SetBackgroundImage(ImageViewWrapper.java:95)
    at anywheresoftware.b4a.objects.ImageViewWrapper.setBitmap(ImageViewWrapper.java:77)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:250)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
    at anywheresoftware.b4a.BA$2.run(BA.java:370)
    at android.os.Handler.handleCallback(Handler.java:873)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6669)


B4X:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

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 Spinner1 As Spinner
    Private imageview1 As ImageView
    'Private imageview2 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("Downloadhomework")
    Activity.Title="Homework DownloadLoader"
    
     InitSpinners
End Sub

Sub Activity_Resume

End Sub

Sub InitSpinners
    Private i As Int
    Private Query1 As String
    Private Curs As Cursor
    'query = "CREATE TABLE SMSlist (Account Text, Names Text,Phone text,Sex, ID INTEGER )"
    'We execute a query for each column and fill the Spinner
    'We use SELECT DISTINCT to have each existing first name in the database only once
    Query1 = "SELECT DISTINCT Class FROM Classes where CLASS NOT LIKE '%S%' ORDER BY Class ASC"
    Curs = Starter.SQL1.ExecQuery(Query1)
    'we add 'no filter' as no selection
    Spinner1.Clear
    Spinner1.Add("Select from the List...")
    
    'we fill the Spinner with the data from the database
    For i = 0 To Curs.RowCount - 1
        Curs.Position = i
        'spnFirstName.Add(Curs.GetString("Account"))
        Spinner1.Add(Curs.GetString("Class"))
        
        'Dim kk As String = Curs.GetString("Names")
        'Log(kk)
    Next
    'spnFirstName.RemoveAt("Select from the List...")
    Curs.Close
    
End Sub
Sub Activity_Pause (UserClosed As Boolean)

End Sub

 


Sub Button1_Click

    
    DownloadImage("http://kccug.com/KabojjaApp/work/P1.png", imageview1)

End Sub

Sub DownloadImage(Link As String, iv As ImageView)
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download(Link)
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        iv.Bitmap = j.GetBitmap
        'Activity.SetBackgroundImage(j.GetBitmap)
    End If
    j.Release

End Sub


Public Sub BytesToImage(bytes() As Byte) As Bitmap
    Dim In As InputStream
    In.InitializeFromBytesArray(bytes, 0, bytes.Length)
    Dim bmp As Bitmap
    bmp.Initialize2(In)
    Return bmp
End Sub

Public Sub ImageToBytes(Image As Bitmap) As Byte()
    Dim out As OutputStream
    out.InitializeToBytesArray(0)
    Image.WriteToStream(out, 100, "JPEG")
    out.Close
    Return out.ToBytesArray
End Sub
 
Top