Android Question Bitmap Error

Emme Developer

Well-Known Member
Licensed User
Longtime User
Hi all! In my app, an user says that application crash, and sent me the log of the error. He has a Huawey y6. I tried with 4 devices, but without any issue. Can anyone helps me? Thanks

B4X:
--------- beginning of system
--------- beginning of main
~i:*** Service (starter) Create ***
Device locale: it
Found 759 strings.
loc it
Found 759 strings.
loc it
~i:** Service (starter) Start **
~i:** Activity (main) Create, isFirst = true **
~i:** Activity (main) Resume **
~i:** Activity (main) Pause, UserClosed = false **
~i:** Activity (popup) Create, isFirst = true **
~i:** Activity (popup) Resume **
~i:** Activity (popup) Pause, UserClosed = true **
~i:** Activity (main) Resume **
~i:** Activity (main) Pause, UserClosed = false **
~i:** Activity (boss) Create, isFirst = true **
~e:boss_activity_create (java line: 440)
~e:java.lang.RuntimeException: Error loading bitmap.
~e:    at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Initialize2(CanvasWrapper.java:538)
~e:    at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Initialize(CanvasWrapper.java:516)
~e:    at anywheresoftware.b4a.keywords.Common.LoadBitmap(Common.java:1315)
~e:    at ed.tactivision.com.boss._activity_create(boss.java:440)
~e:    at java.lang.reflect.Method.invoke(Native Method)
~e:    at java.lang.reflect.Method.invoke(Method.java:372)
~e:    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
~e:    at ed.tactivision.com.boss.afterFirstLayout(boss.java:102)
~e:    at ed.tactivision.com.boss.access$000(boss.java:17)
~e:    at ed.tactivision.com.boss$WaitForLayout.run(boss.java:80)
~e:    at android.os.Handler.handleCallback(Handler.java:739)
~e:    at android.os.Handler.dispatchMessage(Handler.java:95)
~e:    at android.os.Looper.loop(Looper.java:135)
~e:    at android.app.ActivityThread.main(ActivityThread.java:5593)
~e:    at java.lang.reflect.Method.invoke(Native Method)
~e:    at java.lang.reflect.Method.invoke(Method.java:372)
~e:    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
~e:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
java.lang.RuntimeException: Error loading bitmap.
at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Initialize2(CanvasWrapper.java:538)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper.Initialize(CanvasWrapper.java:516)
at anywheresoftware.b4a.keywords.Common.LoadBitmap(Common.java:1315)
at ed.tactivision.com.boss._activity_create(boss.java:440)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
at ed.tactivision.com.boss.afterFirstLayout(boss.java:102)
at ed.tactivision.com.boss.access$000(boss.java:17)
at ed.tactivision.com.boss$WaitForLayout.run(boss.java:80)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5593)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:960)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)

This is the code

B4X:
Dim st() As String = Array As String(Utils.Tr("ut_124"),Utils.Tr("ut_125"),    Utils.Tr("ut_122"))
    Dim img() As String = Array As String("map.jpg","mapdz.png","map2.png")

For i = 0 To st.Length-1
'other stuff
Dim imv As JSTouchImageView
        imv.Initialize
        p.AddView(imv,0,0,VP.Width,VP.Height)
        imv.ScaleType =  imv.SCALE_TYPE_FIT_CENTER
        imv.Tag = i

If File.Exists(File.DirInternal,img(i)) Then
            imv.ImageBitmap = LoadBitmap(File.DirInternal,img(i))
            pb.RemoveView
        Else
            DownloadImage(i, pb, img(i))
        End If

'other stuff
next
'...
end sub

Sub DownloadImage (ind As Int, pb As ProgressBar, name As String)
    Dim Job As HttpJob
    Job.Initialize(name,Me)
    Job.Tag = Array(ind,pb)
    Job.Download("mysite"&name)
End Sub

Sub JobDone (job As HttpJob)
    If job.Success Then
        Dim ar() As Object = job.Tag
        Dim ind As Int = ar(0)
        Dim pb As ProgressBar = ar(1)
        pb.RemoveView
        Dim out As OutputStream = File.OpenOutput(File.DirInternal,job.JobName,False)
        File.Copy2(job.GetInputStream, out)
        out.Close '<------ very important
        RefreshZoomImage(ind,job.GetBitmap)
    End If
   
End Sub

Sub RefreshZoomImage (ind As Int,bitm As Bitmap)
    Dim p As Panel = PC.GetPageObject(ind)
    Dim imv As JSTouchImageView
    imv.Initialize
    p.AddView(imv,0,0,VP.Width,VP.Height)
    imv.ScaleType =  imv.SCALE_TYPE_FIT_CENTER
    imv.ImageBitmap = bitm
End Sub
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
What version of Android does the user who is seeing the crash have on his device? What version do you have in your "targetSdkVersion" setting in your app manifest?

If they are using Android Marshmallow & up (v6.0+) & your "targetSdkVersion" is set to 23 or above, you'll need to use runtime permissions to get the WRITE_EXTERNAL_STORAGE permission (which will implicitly also give you READ_EXTERNAL_STORAGE permission) There's a tutorial on runtime permissions here: Runtime Permissions (Android 6.0+ Permissions)

A quick & easy workaround is to change your "targetSdkVersion" setting in the manifest to something lower than 23.

- Colin.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
If they are using Android Marshmallow & up (v6.0+) & your "targetSdkVersion" is set to 23 or above, you'll need to use runtime permissions to get the WRITE_EXTERNAL_STORAGE permission (which will implicitly also give you READ_EXTERNAL_STORAGE permission) There's a tutorial on runtime permissions here: Runtime Permissions (Android 6.0+ Permissions)
He is using File.DirInternal which doesn't require any permission.

Don't call Job.GetBimap unless you are sure that the images are small. It is better to call Job.GetBitmapResize.
 
Upvote 0
Top