Android Question Unable to find resource ID #0x42 - MapFragment

katrad

Member
Licensed User
Longtime User
I hate to leave questions, but, I can't figure out how to fix this. Thanks in advance for help.

I have several actionbar tabs (4 of them), and on one of them I have a panel that I created using the designer. I want to show a googlemap on.

I'm using B4A vers. 5.50, Googlemaps library version 1.01, I checked my resource directory and it appears fine, and I also checked my manifest page. Everything seems right to me.

Here's the code:
B4X:
Sub Globals
...
    ' Map
    Dim Gmap As GoogleMap
    Dim MFrag As MapFragment
    Dim MapPanel As Panel
...
End Sub

Sub Activity_Create(FirstTime As Boolean)
...
    vp.Panels(2).LoadLayout("Det_Map")
    ' Map Stuff
    Log("Loading Det_Map")
    If MFrag.IsGooglePlayServicesAvailable = False Then
        ToastMessageShow("Google Play services not available.", True)
    Else
        MFrag.Initialize("Maps", MapPanel)     
    End If
    '
    vp.Panels(3).LoadLayout("Det_Officers")
    SVOfficers.panel.loadlayout("OfcDetPanel")
    SVOfficers.Panel.Height = OfcPnlDetail.Height  
    bar.SelectedIndex = currentPage
    strLocal = Main.CurrentLocal
    Load_Data(strLocal)
End Sub

All of this code runs, but right after it does it gets the error "Unfortunately, program has stopped"

It never runs this part:
B4X:
Sub Maps_Ready
    Log("map ready")
    Try
       Gmap = MFrag.GetMap
    Catch
       ToastMessageShow("Error initializing map.", True)
    End Try   
    If Gmap.IsInitialized = False Then
        ToastMessageShow("Error initializing map.", True)
    Else
        Gmap.AddMarker(36, 15, "Hello!!!")
        Dim cp As CameraPosition
        cp.Initialize(36, 15, Gmap.CameraPosition.Zoom)
        Gmap.AnimateCamera(cp)
    End If
End Sub

If I comment out this line, the program runs (except no map and of course Maps_Ready won't run)
B4X:
'        MFrag.Initialize("Maps", MapPanel)

Here's the log:
B4X:
...
Version D/L Complete: true      
** Activity (main) Pause, UserClosed = false **
** Activity (detail_info) Create, isFirst = true **
Loading Det_Map
** Activity (detail_info) Resume **
android.content.res.Resources$NotFoundException: Unable to find resource ID #0x42
    at android.content.res.Resources.getResourceName(Resources.java:2713)
    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:882)
    at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
    at android.app.BackStackRecord.run(BackStackRecord.java:684)
    at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1453)
    at android.app.FragmentManagerImpl$1.run(FragmentManager.java:443)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:146)
    at android.app.ActivityThread.main(ActivityThread.java:5487)
    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:1283)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
    at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Resume **

Thanks in advance, any help is greatly appreciated.
-Dale
 
Last edited:

katrad

Member
Licensed User
Longtime User
WOW, that did work. Well, since it's not working within the tabs, do you think there can be a workaround for that? Havent, tried this, but, all I can think is to pop it at the same location I have for it on that tab and just do some quick removing / adding when tabs are switched. That's going to screw up that scrolling effect the tabs have. Any ideas?? BTW, Thank You!!
 
Upvote 0

Indy

Active Member
Licensed User
Longtime User
Does it work if you add the map to the activity instead of the ViewPager?
Hi Erel,

This is exactly the problem I'm having. For me the map does work if assigned to the Activity but not if I try and add it to a tab.
 
Upvote 0

katrad

Member
Licensed User
Longtime User
I changed some things around here, and it might be live-able. Will loose the left / right scroll for the tab, but, I probably would have anyway (since its a map). I load one panel to match the vp panel, and then load the layout I was using on it, and THEN reference the mappanel from the designer I had. Here's what I have so far.

B4X:
Sub bar_TabChanged(Index As Int, STab As StdTab)
    If vp.currentPage <> Index Then    vp.ScrollTo(Index, False)
    If Index = 2 Then
        MapPanelTest.Initialize("")
        Activity.AddView(MapPanelTest, 5dip,5dip,100%x-10dip, 100%y-96dip)
        MapPanelTest.LoadLayout("Det_Map")     
        If MFrag.IsGooglePlayServicesAvailable = False Then
          ToastMessageShow("Google Play services not available.", True)
       Else
          MFrag.Initialize("Maps", MapPanel) 
       End If
    End If
End Sub

Not quite sure how to remove this view when another tab is selected.

I have to quit for awhile, its earlier here, and I've been working on this (not this problem, just programming) since yesterday morning. Thanks All. I'll post back. I think this will help others in this problem.
 
Last edited:
Upvote 0
Top