Find error with Basic4Android ?

Prosg

Active Member
Licensed User
Longtime User
Hello,

Google Play user send me an error in my app:

java.lang.IllegalArgumentException
emplacement : android.graphics.Bitmap.nativeCreate
java.lang.RuntimeException: java.lang.IllegalArgumentException: width and height must be > 0
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:149)
at anywheresoftware.b4a.objects.WallpaperInternalService$LWManager.raiseEvent(WallpaperInternalService.java:99)
at anywheresoftware.b4a.objects.WallpaperInternalService$B4AEngine.onOffsetsChanged(WallpaperInternalService.java:274)
at android.service.wallpaper.WallpaperService$Engine.doOffsetsChanged(WallpaperService.java:717)
at android.service.wallpaper.WallpaperService$IWallpaperEngineWrapper.executeMessage(WallpaperService.java:905)
at com.android.internal.os.HandlerCaller$MyHandler.handleMessage(HandlerCaller.java:61)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalArgumentException: width and height must be > 0
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:477)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.InitializeMutable(CanvasWrapper.java:543)
at mangawallpaper.yukie.wallpaperservice._vvvvvvvvvvvvvvvv2(wallpaperservice.java:190)
at mangawallpaper.yukie.wallpaperservice._lwm_offsetchanged(wallpaperservice.java:113)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
... 14 more

It's not so easy to know what line of my program must be change cause it's give line number in java

the code of offset

B4X:
Sub LWM_OffsetChanged (Engine As LWEngine)
    If image.IsInitialized AND resized.IsInitialized = False Then
        resized = ResizeImage(image, Engine.FullWallpaperWidth, Engine.FullWallpaperHeight)
    End If
    If resized.IsInitialized Then
'        Engine.Rect.Left = -Engine.CurrentOffsetX
'        Engine.Rect.Top = -Engine.CurrentOffsetY
'        Engine.Rect.Right = -Engine.CurrentOffsetX + Engine.FullWallpaperWidth
'        Engine.Rect.Bottom = -Engine.CurrentOffsetY + Engine.FullWallpaperHeight
        Engine.Rect.Left = -(Engine.FullWallpaperWidth - actualImageWidth) / 2
        Engine.Rect.Top = 0
        Engine.Rect.Right = Engine.Rect.Left + Engine.FullWallpaperWidth
        Engine.Rect.Bottom = Engine.FullWallpaperHeight
        Engine.Canvas.DrawBitmap(resized, Null, Engine.Rect)
    End If
    Engine.RefreshAll
End Sub
 
Last edited:

bluejay

Active Member
Licensed User
Longtime User
Hi Fili

In your project folder there a folder called Objects which contains a folder called src. If you drill down you will find the wallpaperservice.java which was generated by B4A when translating the Basic program code.

It is usually easy to see which java statement relates to which basic statement and I am not a java programmer.

Hope that helps.

bluejay
 
Upvote 0

Prosg

Active Member
Licensed User
Longtime User
Here is the code for resized image :

B4X:
Sub ResizeImage(original As Bitmap, TargetX As Int, TargetY As Int) As Bitmap
    Dim origRatio As Float = original.Width / original.Height
    Dim targetRatio As Float = TargetX / TargetY
    Dim scale As Float
    
    If targetRatio > origRatio Then
        scale = TargetY / original.Height
    Else
        scale = TargetX / original.Width
    End If
    
    Dim c As Canvas
    Dim b As Bitmap
    b.InitializeMutable(TargetX, TargetY)
    c.Initialize2(b)
    'set the background
    c.DrawColor(Colors.LightGray)
    Dim r As Rect
    Dim w = original.Width * scale, h = original.Height * scale As Int
   actualImageWidth = w
   actualImageHeight = h
    r.Initialize(TargetX / 2 - w / 2, TargetY / 2 - h / 2, TargetX / 2 + w / 2, TargetY / 2+ h / 2)
    c.DrawBitmap(original, Null, r)
    Return b
End Sub

I need to have a try... catch ? i don't understand how a bitmap size could be invalide ?
 
Upvote 0

Prosg

Active Member
Licensed User
Longtime User
Thank a lot for your help.

This app have now 100 - 500 download in one week so i try to have no bug :)
 
Upvote 0
Top