How to capture an error "out of memory"

bgsoft

Well-Known Member
Licensed User
Longtime User
Hello:

In a program I put an image to a TouchImageView.
And TouchImageView works well. But when I look at several images, at the end I get this error:

before loading Bitmap1

main_pintarunaimagen (java line: 987)
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:652)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.InitializeSample(CanvasWrapper.java:525)
at jesus.galerialist.main._pintarunaimagen(main.java:987)
at jesus.galerialist.main._button_click(main.java:579)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:155)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:151)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:59)
at android.view.View.performClick(View.java:4232)
at android.view.View$PerformClick.run(View.java:17298)
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:4921)
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:1027)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
at dalvik.system.NativeStart.main(Native Method)



I copy a part of the program where the image charge.

B4X:
   Dim Bitmap1 As Bitmap
   
   Log("before loading Bitmap1")

   Try
     Bitmap1.InitializeSample (path,Filename,300%x,300%y)  
    Catch
      Log("error loading Bitmap1")
     ToastMessageShow("Falta memoria para cargar la imagen" ,True)  
    End Try

   Log("After load")

I know that if instead of putting 300% x, put less would not happen, but the problem is that much lower quality.

I try to capture the error with a Try Catch, but as you have seen in the log, fails to enter the Catch.

The image when I go out, so I download it:


B4X:
   Dim Bitmap1 As Bitmap
   Bitmap1.Initialize3(ImagenVacia.Bitmap) ' ImagenVacia.Bitmap = 1 pixel image
   
   Try
     TouchImageView1.SetBitmap(Bitmap1)  
       DoEvents
     TouchImageView1.RemoveView
   Catch
     Log("error al quitar imagen")
   End Try

Any ideas to capture the error or the memory is full?

thanks

Jesús
 
Top