Android Question Can Someone Please Decipher This Error Message for me?

Shadow&Max

Active Member
Licensed User
Longtime User
Here's the line of code that's causing the error. This is a line from the code Erel sent regarding image rotation.

NewImage = bmp.RunMethod("createBitmap", Array(original, 0, 0, original.Width, original.Height, matrix, True))

This is in the following code:

B4X:
Sub RotateImage(original As Bitmap, degree As Float) As Bitmap
  Dim matrix As JavaObject
  matrix.InitializeNewInstance("android.graphics.Matrix", Null)
  matrix.RunMethod("postRotate", Array(degree))
  hw = original.Width
  hh = original.Height
  Dim bmp As JavaObject
  bmp.InitializeStatic("android.graphics.Bitmap")
  Dim NewImage As Bitmap
  NewImage = bmp.RunMethod("createBitmap", Array(original, 0, 0, original.Width, original.Height, matrix, True))
  Return NewImage
End Sub

This line works most of the time. I know the image is saved on the drive, then brought in and rotated. This dies on the line above. But here are the stats of this action: The bitmap file's dimensions are 4320 x 2432 (camera res).

Here's the error dump:

** Activity (addedit) Resume **
Downsampling image due to lack of memory.
Downsampling image due to lack of memory.
Error occurred on line: 2629 (addedit)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:109)
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:636)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:162)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:158)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:66)
at android.view.View.performClick(View.java:4456)
at android.view.View$PerformClick.run(View.java:18462)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5102)
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:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.OutOfMemoryError
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:835)
at android.graphics.Bitmap.createBitmap(Bitmap.java:812)
at android.graphics.Bitmap.createBitmap(Bitmap.java:744)


I know it's an out of memory error... how come? I can downsample things that come from the phone, but what I don't understand is that the phone can store hundreds of these. Why's this failing?

Thanks in advance!
 
Last edited:

Shadow&Max

Active Member
Licensed User
Longtime User
Never mind... I'm just going to downsample the photo after it's taken...
 
Upvote 0
Top