Issue
I'm a novice android programmer.
Let me give some context.
My project uses ActionBarSherlock.
- I have an activity (Activity1) that contains two fragments - a SherlockListFragment and a SherlockFragment containing a google maps MapView (essentially a MapFragment).
- Search results are displayed in the list fragment and the map fragment, and an action bar options button toggles the currently showing Fragment between the list and the map.
- Selecting an item in the list or the map of search results starts a new activity (Activity2) displaying data from the selected item.
- This new activity has a similar flow: a fragment to show the data, and a map fragment to show a location - toggled by an action bar options button.
The problem:
- I can select a list item in the search results (Activity1) list fragment and the details page (Activity2) is started successfully.
- When I select a map item from the map overlay in (Activity1), the app crashes, and I get the stacktrace shown below.
What I've tried so far:
- I've searched for "map has zero size" and many permutations of the same search including "android" and "illegalstateexception" and various lines of the stacktrace and I've examined results that don't even relate to android but relate to the google maps apis in general, and I have not been able to find anything or anyone anywhere who has encountered this error except for at this url http://www.androidpub.com/1551654 But I don't know korean, and Google translate wasn't much help.
- I've tried to find some snippets of the source code to see what's going on, but that turned up nothing.
- I've added logs in my code to try and pinpoint where the exception occurs, and all that I've been able to find is that it occurs sometime after (Activity2) the details activity starts, that is, after onCreate() is called. And both the details fragment and map fragment have booth been successfully instantiated within onCreate(). I haven't been able to find a place in my code to even catch the exception. So for all that I can see, this exception appears to be entirely a bug in google's MapView code, but if I've made a mistake anywhere, please do show it. I'm open to help from anyone who can tell me what is going on here.
So, in summary. The crash occurs when going from an activity (Activity1) with a currently showing mapview to another activity (Activity2) that also hosts a fragment containing another mapview. But the crash does not occur when going from the list fragment showing in (Activity1) to the other activity (Activity2) containing another map fragment.
I hope this is enough detail. If you have any questions, comment please.
D/memalloc( 121): /dev/pmem: Allocated buffer base:0x4215c000 size:2088960 offset:4177920 fd:66
D/memalloc(30944): /dev/pmem: Mapped buffer base:0x5b4f5000 size:6266880 offset:4177920 fd:164
D/AndroidRuntime(30944): Shutting down VM
W/dalvikvm(30944): threadid=1: thread exiting with uncaught exception (group=0x40aaa228)
E/AndroidRuntime(30944): FATAL EXCEPTION: main
E/AndroidRuntime(30944): java.lang.IllegalStateException: Map has zero size
E/AndroidRuntime(30944): at android_maps_conflict_avoidance.com.google.googlenav.map.Map.drawMap(Map.java:818)
E/AndroidRuntime(30944): at com.google.android.maps.MapView.drawMap(MapView.java:1091)
E/AndroidRuntime(30944): at com.google.android.maps.MapView.onDraw(MapView.java:522)
E/AndroidRuntime(30944): at android.view.View.draw(View.java:11071)
E/AndroidRuntime(30944): at android.view.View.getDisplayList(View.java:10462)
E/AndroidRuntime(30944): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2605)
E/AndroidRuntime(30944): at android.view.View.getDisplayList(View.java:10425)
E/AndroidRuntime(30944): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2605)
E/AndroidRuntime(30944): at android.view.View.getDisplayList(View.java:10425)
E/AndroidRuntime(30944): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2605)
E/AndroidRuntime(30944): at android.view.View.getDisplayList(View.java:10425)
E/AndroidRuntime(30944): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2605)
E/AndroidRuntime(30944): at android.view.View.getDisplayList(View.java:10425)
E/AndroidRuntime(30944): at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:2605)
E/AndroidRuntime(30944): at android.view.View.getDisplayList(View.java:10425)
E/AndroidRuntime(30944): at android.view.HardwareRenderer$GlRenderer.draw(HardwareRenderer.java:879)
E/AndroidRuntime(30944): at android.view.ViewRootImpl.draw(ViewRootImpl.java:1948)
E/AndroidRuntime(30944): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1654)
E/AndroidRuntime(30944): at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2498)
E/AndroidRuntime(30944): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(30944): at android.os.Looper.loop(Looper.java:154)
E/AndroidRuntime(30944): at android.app.ActivityThread.main(ActivityThread.java:4894)
E/AndroidRuntime(30944): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(30944): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(30944): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
E/AndroidRuntime(30944): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
E/AndroidRuntime(30944): at dalvik.system.NativeStart.main(Native Method)
E/EmbeddedLogger( 254): App crashed! Process: com.myapp.android
E/EmbeddedLogger( 254): App crashed! Package: com.myapp.android v5 (2.0)
E/EmbeddedLogger( 254): Application Label: myapp
W/ActivityManager( 254): Force finishing activity com.myapp.android/.activity.InfoActivity
W/ActivityManager( 254): Force finishing activity com.myapp.android/.activity.SearchActivity
Solution
At this point in my experience, the only way to avoid this bug, is to not use MapViews inside Fragments. Moving a MapView around at all by whether animation or tampering with it's position once it's been added to a parent view has always caused me problems. The most effective way I've found is to toggle between a map and another view where the MapActivity manages the MapView and a fragment manages the other View. I reimplemented the same feature again, and this has worked with no problems. However, I would observe that this is a workaround for an issue with an unknown cause (very likely a bug in the android maps API).
Answered By - Adam J
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.