Android Question Bitmap Initialize

dagodom

Member
Licensed User
Longtime User
HI,

I have some problem when i try to write bitmap in instruction "imgdown.writetostream ..." :

java.lang.RuntimeException: Object should first be initialized (Bitmap).

I try every initialize but i can't resolve error.

I'm doing something wrong, can someone give me a help ? thank you

B4X:
Sub gestphoto(response)
   
    Dim parser As JSONParser
    parser.Initialize(response)
    Dim root As Map = parser.NextObject
    Dim response As String = root.Get("response")
    If response == 0 Then
        Return
    End If
   
    Dim filename As String = root.Get("filename")
    Dim imgdown As Bitmap = root.Get("photo")

    Dim TargetDir As String
    If File.ExternalWritable Then TargetDir = File.DirDefaultExternal Else TargetDir = File.DirInternal
    If File.Exists(TargetDir, filename) == True Then
        File.delete(TargetDir, filename)
    End If   
    Dim Out As OutputStream
    Out = File.OpenOutput(TargetDir, filename, False)
    imgdown.WriteToStream(Out, 100, "JPEG")
    Out.Close
 

dagodom

Member
Licensed User
Longtime User
Ahhh, ok, a "litte mistake"

Thank you, i search an alternative

this is output:


Error occurred on line: 529 (Main)
java.lang.RuntimeException: Object should first be initialized (Bitmap).
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:668)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:334)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:244)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:132)
at anywheresoftware.b4a.BA$3.run(BA.java:334)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5603)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
 
Upvote 0

dagodom

Member
Licensed User
Longtime User
What do you mean ?
what is log(root)?
I thought it was the log that I paste....
 
Upvote 0

dagodom

Member
Licensed User
Longtime User
ah, I did not understand
The code I have changed and I can not recreate the same conditions.
I changed the type of data returned by the server and run the output in this way:
(perhaps not the best way, but I have little experience with the language)
anyway thanks for the time

B4X:
Sub gestphoto(message)
   
    Dim response As String
    response = message.SubString2(0,1)
    If response == "0" Then
       Return
    End If
    Dim filename As String = message.SubString2(1,100)
    filename = filename.Trim
    Dim imgstring As String = message.SubString(101)
   
    Dim TargetDir As String = setTargetDir
    If File.Exists(TargetDir, filename) == True Then
        File.delete(TargetDir, filename)
    End If   
   
    Dim su As StringUtils
    Dim buffer() As Byte
    Dim b As Bitmap
    buffer = su.DecodeBase64(imgstring)
    Dim In As InputStream
    In.InitializeFromBytesArray(buffer, 0, buffer.Length)
    b.Initialize2(In)   
    Dim imgdown As Bitmap = b
    Dim Out As OutputStream
    Out = File.OpenOutput(TargetDir, filename, False)
    imgdown.WriteToStream(Out, 100, "JPEG")
    Out.Close
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…