Android Question got outofmemory error

Mrjoey

Active Member
Licensed User
Longtime User
B4X:
java.lang.OutOfMemoryError
    at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:650)
    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:722)
    at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Initialize2(CanvasWrapper.java:519)
    at b4a.example.open._audio_click(open.java:473)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:173)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:858)
    at anywheresoftware.b4a.keywords.Common.CallSubNew3(Common.java:823)
    at b4a.example.open._l2albums_click(open.java:1293)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:173)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:858)
    at anywheresoftware.b4a.keywords.Common.CallSubNew3(Common.java:823)
    at b4a.example.clschecklist._pnlsv_click(clschecklist.java:3326)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:173)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:157)
    at anywheresoftware.b4a.agraham.reflection.Reflection$2.onClick(Reflection.java:985)
    at android.view.View.performClick(View.java:4211)
    at android.view.View$PerformClick.run(View.java:17267)
    at android.os.Handler.handleCallback(Handler.java:615)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4898)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
    at dalvik.system.NativeStart.main(Native Method)

i ve got this error , i realise that this error comes from the bitmap wich load the song cover bitmap
this is how i create the cover bitmap
B4X:
If MP.Cover = Null Then
ImgCover.Visible = False
Else
            Dim In As InputStream
            In.InitializeFromBytesArray(MP.Cover,0,MP.Cover.Length)
            Dim bmp As Bitmap
            bmp.Initialize2(In)
            ImgCover.Bitmap = CreateScaledBitmap(bmp,ImgCover.Width,ImgCover.Height)
            ImgCover.Visible = True
            In.Close
           
End If

what is the best way to create the bitmap and maintain the memory happy? tnx
 

Mrjoey

Active Member
Licensed User
Longtime User
can u give me a quick idea on how to write an outstream to a file to load in loadbitmapsample?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
Dim out As OutputStream = File.OpenOutput(File.DirDefaultExternal,Main.pathimages&filename, False)
File.Copy2(job.GetInputStream, out)
out.Close '<------- very important
 
Upvote 0
Top