TabHost and MapView

osasigbinedion

Member
Licensed User
Longtime User
I have an application with a tab for maps. It was working and it stopped working. I can't figure out the problem.

Side note: This code snippet works with the mapview added to an activity.

i.e Activity.AddView(Mview, 0, 0, 100%x, 100%y)

This is my code...

Sub AddMapTab
Dim tabIcon, tabIconselected As Bitmap

If File.ExternalWritable=False Then
' OSMDroid requires the use of external storage to cache tiles
' if no external storage is available then the MapView will display no tiles
Log("WARNING NO EXTERNAL STORAGE AVAILABLE")
End If
mView.Initialize("")

mView.SetZoomEnabled(True)
mView.SetMultiTouchEnabled(True)
mView.Zoom=12
mView.SetCenter(45.340633, -75.719283)
tabIcon = LoadBitmapSample(File.DirAssets, "map.png",TabWidth, TabHeight)
tabIconselected = LoadBitmapSample(File.DirAssets, "mapselected.png",TabWidth, TabHeight)
TabHost1.AddTabWithIcon2("", tabIcon, tabIconselected, mView)

End Sub
 

osasigbinedion

Member
Licensed User
Longtime User
Thanks Klaus,

I tried that and got the same result.... the tiles don't appear the map area is blank... I even set the tilesource to Mapnik but the outcome remains the same.

I am running out of ideas because I had that functionality working for a while and it is gone....I am still troubleshooting and open to trying new things.

Cheers
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Export your project as a .zip file and upload it to this thread and i bet we can get it fixed...

Martin.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
This looks tricky!

Here's the exception that appears repeatedly in the unfiltered log:

RejectedExecutionException
java.util.concurrent.RejectedExecutionException: pool=0/8, queue=0
at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:1961)
at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:794)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1315)
at org.osmdroid.tileprovider.modules.MapTileModuleProviderBase.loadMapTileAsync(MapTileModuleProviderBase.java:119)
at org.osmdroid.tileprovider.MapTileProviderArray.getMapTile(MapTileProviderArray.java:117)
at org.osmdroid.views.overlay.TilesOverlay$1.handleTile(TilesOverlay.java:167)
at org.osmdroid.util.TileLooper.loop(TileLooper.java:36)
at org.osmdroid.views.overlay.TilesOverlay.drawTiles(TilesOverlay.java:145)
at org.osmdroid.views.overlay.TilesOverlay.draw(TilesOverlay.java:133)
at org.osmdroid.views.overlay.OverlayManager.onDraw(OverlayManager.java:114)
at org.osmdroid.views.MapView.dispatchDraw(MapView.java:867)
at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
at android.view.View.draw(View.java:6905)
at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
at android.view.ViewGroup.drawChild(ViewGroup.java:1644)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
at android.view.View.draw(View.java:6905)
at android.widget.FrameLayout.draw(FrameLayout.java:357)
at android.view.ViewGroup.drawChild(ViewGroup.java:1646)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373)
at android.view.View.draw(View.java:6905)
at android.widget.FrameLayout.draw(FrameLayout.java:357)
at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1908)
at android.view.ViewRoot.draw(ViewRoot.java:1554)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1263)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1892)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3835)
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:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)

Looking at the OSMDroid source all the quoted line numbers refer to code that draws various parts of the map.
Suspecting a timing issue i updated your AddMaptab Sub:

B4X:
Sub AddMapTab
   Dim tabIcon, tabIconselected As Bitmap
   mapPanel.Initialize("")
   mView.Initialize("")
   mapPanel.AddView(mView,0,0,100%x, 100%y)   
   mView.SetZoomEnabled(True)
      mView.SetMultiTouchEnabled(True)
   mView.Zoom=12
    mView.SetCenter(45.340633, -75.719283)
   tabIcon = LoadBitmapSample(File.DirAssets, "map.png",TabWidth, TabHeight)
   tabIconselected = LoadBitmapSample(File.DirAssets, "mapselected.png",TabWidth, TabHeight)
   TabHost1.AddTabWithIcon2("", tabIcon, tabIconselected, mapPanel)
   
   Log("Pause here") ' debugger breakpoint added here
End Sub

Running the project again in debug mode it reaches that line without the original exception but now logs:

java.lang.RuntimeException: Object should first be initialized (GeoPoint).


at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:45)
at uk.co.martinpearman.b4a.osmdroid.util.wrappers.GeoPointWrapper.toString(GeoPointWrapper.java:98)
at java.lang.String.valueOf(String.java:1860)
at anywheresoftware.b4a.debug.Debug.objectToString(Debug.java:380)
at anywheresoftware.b4a.debug.Debug.writeGlobals(Debug.java:299)
at anywheresoftware.b4a.debug.Debug.sendBPData(Debug.java:280)
at anywheresoftware.b4a.debug.Debug.access$9(Debug.java:275)
at anywheresoftware.b4a.debug.Debug$1.run(Debug.java:252)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at anywheresoftware.b4a.Msgbox.waitForMessage(Msgbox.java:211)
at anywheresoftware.b4a.Msgbox.debugWait(Msgbox.java:156)
at anywheresoftware.b4a.debug.Debug.wait(Debug.java:209)
at anywheresoftware.b4a.debug.Debug.reachBP(Debug.java:256)
at anywheresoftware.b4a.debug.Debug.ShouldStop(Debug.java:228)


at osas.track24.scctandroid.main._addmaptab(main.java:1026)
at osas.track24.scctandroid.main._activity_create(main.java:404)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
at osas.track24.scctandroid.main.afterFirstLayout(main.java:84)
at osas.track24.scctandroid.main.access$100(main.java:16)
at osas.track24.scctandroid.main$WaitForLayout.run(main.java:72)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3835)
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:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)

The device screen is dimmed and showing a progress dialog and underneath i can see the map with tiles loaded.
Stepping through the Activity with the debugger it now logs the 'Object should first be initialized (GeoPoint)' exception each time i click the 'step to next line' button.

Clicking the 'continue code execution' button stops the debug session and your MapView is displaying tiles but any attempt to drag the map causes the original RejectedExecutionException exception to be logged.

I think one of your Service modules is causing the exceptions, and it's a timing issue - the MapView has not been initialized before it's being used or referenced...
Is a Service trying to get a GeoPoint property from the MapView before that GeoPoint property is available?

Martin.
 
Upvote 0

osasigbinedion

Member
Licensed User
Longtime User
The Tabs are created as soon as the activity is created, my mapview object is already initialized before i start updating the map with positions...
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Amazing - how on earth would you have worked that out from either of the two exceptions i quoted in my post?

Anyway - fixed is fixed.

Martin.
 
Upvote 0

osasigbinedion

Member
Licensed User
Longtime User
I know eh.


I just basically started taking away new features I made in a bit to strip it down to the way it was when the mapping functionality was working.
 
Upvote 0
Top