Android Question ContentChooser Bitmap Puzzler

mmieher

Active Member
Licensed User
Longtime User
Cannot figure out what the problem is here:
B4X:
Private Sub SelectPicture As ResumableSub
    LogSub("SelectPicture")
    'Dim img As ImageView    '    now up there in the Class_Globals -- no difference
    img.Initialize("")
    
    cc.Initialize("PhotoChoo")
    cc.Show("image/*","The Title when 'there is more than one application'.  Never seems to show anywhere.")
    Wait For PhotoChoo_Result (Success As Boolean, cDir As String, FileName As String)
    If Success Then
        Log("photochooser SUCCESS!")
        Log("cDir = " & cDir & "   FileName = " & FileName)
        
        img.Bitmap = LoadBitmapSample(cDir,FileName, 35dip, 35dip)
        
    Else
        Log("photochooser CANCEL")
    End If
    
    Return img.Bitmap
    
End Sub

App crashes on line 13 img.Bitmap = ...
B4X:
NativeAlloc concurrent copying GC freed 18228(796KB) AllocSpace objects, 9(180KB) LOS objects, 49% free, 6049KB/11MB, paused 826us total 184.050ms
WaitForGcToComplete blocked ProfileSaver on ProfileSaver for 17.229ms
running waiting messages (1)
photochooser SUCCESS!
cDir = ContentDir   FileName = content://com.google.android.apps.docs.storage/document/acc%3D1%3Bdoc%3Dencoded%3DqVsxR8Lfqe89zYS%2BaAK%2F6VUymadYmrFFIg4uELyYRnAJaONVMQ%3D%3D
A resource failed to call release. 
** Activity (main) Resume **
B4xMain 12:01:54 Page_Resume
Skipped 54 frames!  The application may be doing too much work on its main thread.
claimShared: Ask to claim region [0x3f92f6000 0x3f9adf000]
Davey! duration=931ms; Flags=0, IntendedVsync=1496669980015, Vsync=1497569979979, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=1497573218300, AnimationStart=1497573257800, PerformTraversalsStart=1497574919500, DrawStart=1497574990600, SyncQueued=1497577083300, SyncStart=1497577958900, IssueDrawCommandsStart=1497578662200, SwapBuffers=1497588805200, FrameCompleted=1497602219700, DequeueBufferDuration=10828100, QueueBufferDuration=911300, GpuCompleted=1485296797100, 
Error occurred on line: 52 (B4XLoadingIndicator)
java.lang.ClassCastException: android.graphics.Bitmap cannot be cast to anywheresoftware.b4a.objects.drawable.CanvasWrapper$BitmapWrapper
    at com.marcsmart.aaphonelist.mcomm$ResumableSub_CreateNewText.resume(mcomm.java:2152)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43)
    at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:267)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1773)
    at android.os.Handler.handleCallback(Handler.java:938)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:223)
    at android.app.ActivityThread.main(ActivityThread.java:7656)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
java.net.SocketException: Socket closed

Help me please, Davey!
 

William Lancee

Well-Known Member
Licensed User
Longtime User
Just to let you know, the following seems to work fine, so may be something to do with ContentChooser.

B4X:
    Dim img As ImageView    '    now up there in the Class_Globals -- no difference
    img.Initialize("")
    Activity.AddView(img, 0,  0, 350dip, 350dip)
    
    img.Bitmap = LoadBitmapResize(File.DirAssets,"picasso.jpg", 350dip, 350dip, True)
'    img.Bitmap = LoadBitmapSample(File.DirAssets,"picasso.jpg", 350dip, 350dip)

'works either way, of course look different
 
Upvote 0
Top