Android Question ContentChooser

Guenter Becker

Active Member
Licensed User
Hello,
my B4XPages App is using ContentChooser to retrive an Image from the phones gallery to an imageview. In the manifest Version 28 is targeted and in the Pages creation sub the Chooser Object is initialized.
If I click on my "Open Gallery" Button the chooser is opened an let me choose an image from the gallery. After selecting the image and clicking on the upper right OK Button the App crashes with this error message in the log window. I tried different images.

....

Error occurred on line: 606 (B4XPagesManager)
java.lang.ClassCastException: anywheresoftware.b4a.objects.collections.Map$MyMap cannot be cast to java.lang.String
at anywheresoftware.b4a.keywords.Common.getComponentBA(Common.java:1218)
at anywheresoftware.b4a.keywords.Common.SubExists(Common.java:1007)
at anywheresoftware.b4a.objects.B4XViewWrapper$XUI.SubExists(B4XViewWrapper.java:722)
at TechDoc.FDM.b4xpagesmanager._backgroundstatechanged(b4xpagesmanager.java:982)
at TechDoc.FDM.b4xpagesmanager._activity_pause(b4xpagesmanager.java:593)
at TechDoc.FDM.b4xpagesdelegator._activity_pause(b4xpagesdelegator.java:78)
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 TechDoc.FDM.main.onPause(main.java:275)
at android.app.Activity.performPause(Activity.java:7497)
at android.app.Instrumentation.callActivityOnPause(Instrumentation.java:1421)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4907)
at android.app.ActivityThread.-wrap20(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1946)
at android.os.Handler.dispatchMessage(Handler.java:109)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7367)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:469)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:963)
sending message to waiting queue (OnActivityResult)
running waiting messages (1)

....

If I use the code below then the wait is done. The sub Chooser_Result is not reached I think due to fired error before.

The Code:
Private Sub BTGallery_Click
    Chooser.Show("image/*", "choose image")
    Wait For CC_Result (Success As Boolean, Dir As String, FileName As String)
    If Success = True Then
        'ImageView1.Bitmap = LoadBitmap(Dir,FileName)
    Else
        ToastMessageShow("No Success :(",True)
    End If
End Sub

Sub Chooser_Result (Success As Boolean, Dir As String, FileName As String)
    
End Sub
 

Robert Valentino

Well-Known Member
Licensed User
Just wondering?

You did do a
B4X:
Chooser.Initialize("Chooser")
Some place? Not shown in code?

Because your code implies you call it CC

Here is an example from my code
B4X:
    Dim mPickAFile                                 As ContentChooser   

    mPickFile.Initialize("PickFile")                                                                
     mPickFile.Show("text/csv/*", "Pick a file to import")                
                
    Wait For PickFile_Result(Success As Boolean, Dir As String, FileName As String)

    If  Success Then              
     end if

Your code seems to be waiting on CC_Result and if so why do you even have a routine called Chooser_Result

If you are waiting inline you don't need the routine.

Hope this helps
 
Upvote 0

Guenter Becker

Active Member
Licensed User
Thank you for your answer.
The chooser object is initialized in the create page event. I checked this in step debug.
I corrected the wrong wait for.
I tried it again the content chooser opens and if I select an image the app crashes, I got same error message as before with another line number (b4xpagesmanager_backgroundstatechanged (java line: 242)).

open contenchooser:
' get image from gallery
Private Sub BTGallery_Click
    CC.Show("image/*", "choose image")
    Wait For CC_Result (Success As Boolean, Dir As String, FileName As String)
    If Success = True Then
        Log(Dir)
        Log(FileName)
        zimvImage.SetBitmap(LoadBitmap(Dir,FileName))
        TabHost1.CurrentTab=1
    Else
        ToastMessageShow("No Success :(",True)
    End If
End Sub

Error:
** Activity (main) Create, isFirst = true **
Call B4XPages.GetManager.LogEvents = True to enable logging B4XPages events.
** Activity (main) Resume **
** Activity (main) Pause event (activity is not paused). **
b4xpagesmanager_backgroundstatechanged (java line: 242)
java.lang.ClassCastException: anywheresoftware.b4a.objects.collections.Map$MyMap cannot be cast to java.lang.String
    at anywheresoftware.b4a.keywords.Common.getComponentBA(Common.java:1218)
    at anywheresoftware.b4a.keywords.Common.SubExists(Common.java:1007)
    at anywheresoftware.b4a.objects.B4XViewWrapper$XUI.SubExists(B4XViewWrapper.java:722)
    at TechDoc.FDM.b4xpagesmanager._backgroundstatechanged(b4xpagesmanager.java:242)
    at TechDoc.FDM.b4xpagesmanager._activity_pause(b4xpagesmanager.java:151)
    at TechDoc.FDM.b4xpagesdelegator._activity_pause(b4xpagesdelegator.java:53)
    at TechDoc.FDM.main._activity_pause(main.java:399)

Page CLose EVent:
Private Sub B4XPage_CloseRequest As ResumableSub
    If oMyDrawer.oDrawer.LeftOpen=True Then
        oMyDrawer.oDrawer.LeftOpen=False
    End If
    Return True
End Sub
 
Upvote 0

Guenter Becker

Active Member
Licensed User
The problem is in the code that adds the pages (B4XPages.AddPage). Looks like your add adding a Map instead of a page object.

Ok, got the error solution:
in the main page I have Public 'PageMap as Map' where Map is the name of a B4xMap. My fault! This causes the conflict I think the compiler is not amused using Map as a B4xPagesName. I corrected it and now it works. Thank you.
Whish: things will go easier if the error messages are not so cryptic.
 
Upvote 0
Top