petedoyle/android-support-v4-googlemaps — Issue #5: Getting java.lang.IllegalStateException: You are only allowed to have a single MapView in a MapActivity Exception when using MapView for fragments
Author: nikhilpshah
Created: 2012-01-10 10:15:29+00:00
State: open

Hi,
Thank you for providing a hack lib for MapView.
My implementation of mapView is successful except that I get an error when I call
getActivity().onBackPressed();
from another fragment(other then map fragment)
Here is a detailed information about the exception I am getting.

App for: Mobile
Version: Android 2.2
Supporting file used: android-support-v13-r6-googlemaps.jar

Senario:
1. I have created a Activity which extends FramentActivity(supported from the lib provided)
2. I have created 2 fragments.
a. MapFragment - which has its own layout and this layout contains mapview
b. InformationFragment - which has its own layout and DONOT have mapview. it contains table layout and other stuff
3. I have button in layout for InformationFragment which will call getActivity().onBackPressed();

When I press this button or press back button on the device following is the exception I am getting

01-10 09:54:38.141: E/AndroidRuntime(9726): FATAL EXCEPTION: main
01-10 09:54:38.141: E/AndroidRuntime(9726): android.view.InflateException: Binary XML file line #5: Error inflating class
01-10 09:54:38.141: E/AndroidRuntime(9726):	at android.view.LayoutInflater.createView(LayoutInflater.java:513)
01-10 09:54:38.141: E/AndroidRuntime(9726):	at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
01-10 09:54:38.141: E/AndroidRuntime(9726):	at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
01-10 09:54:38.141: E/AndroidRuntime(9726):	at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
01-10 09:54:38.141: E/AndroidRuntime(9726):	at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
01-10 09:54:38.141: E/AndroidRuntime(9726):	at com.mid.kew.activities.MapFragment.onCreateView(MapFragment.java:78)
01-10 09:54:38.141: E/AndroidRuntime(9726):	at android.support.v4.app.FragmentManagerImpl.moveToState(Unknown Source)
01-10 09:54:38.141: E/AndroidRuntime(9726):	at android.support.v4.app.FragmentManagerImpl.moveToState(Unknown Source)
01-10 09:54:38.141: E/AndroidRuntime(9726):	at android.support.v4.app.BackStackRecord.popFromBackStack(Unknown Source)
01-10 09:54:38.141: E/AndroidRuntime(9726):	at android.support.v4.app.FragmentManagerImpl.popBackStackState(Unknown Source)
01-10 09:54:38.141: E/AndroidRuntime(9726):	at android.support.v4.app.FragmentManagerImpl.popBackStackImmediate(Unknown Source)
01-10 09:54:38.141: E/AndroidRuntime(9726):	at android.support.v4.app.FragmentActivity.onBackPressed(Unknown Source)
01-10 09:54:38.141: E/AndroidRuntime(9726):	at com.mid.kew.activities.CustomiseMapMainFragment$1.onClick(CustomiseMapMainFragment.java:66)
01-10 09:54:38.141: E/AndroidRuntime(9726):	at android.view.View.performClick(View.java:2461)
01-10 09:54:38.141: E/AndroidRuntime(9726):	at android.view.View$PerformClick.run(View.java:8888)
01-10 09:54:38.141: E/AndroidRuntime(9726):	at android.os.Handler.handleCallback(Handler.java:587)
01-10 09:54:38.141: E/AndroidRuntime(9726):	at android.os.Handler.dispatchMessage(Handler.java:92)
01-10 09:54:38.141: E/AndroidRuntime(9726):	at android.os.Looper.loop(Looper.java:123)
01-10 09:54:38.141: E/AndroidRuntime(9726):	at android.app.ActivityThread.main(ActivityThread.java:4627)
01-10 09:54:38.141: E/AndroidRuntime(9726):	at java.lang.reflect.Method.invokeNative(Native Method)
01-10 09:54:38.141: E/AndroidRuntime(9726):	at java.lang.reflect.Method.invoke(Method.java:521)
01-10 09:54:38.141: E/AndroidRuntime(9726):	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
01-10 09:54:38.141: E/AndroidRuntime(9726):	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
01-10 09:54:38.141: E/AndroidRuntime(9726):	at dalvik.system.NativeStart.main(Native Method)
01-10 09:54:38.141: E/AndroidRuntime(9726): Caused by: java.lang.reflect.InvocationTargetException
01-10 09:54:38.141: E/AndroidRuntime(9726):	at com.google.android.maps.MapView.(MapView.java:238)
01-10 09:54:38.141: E/AndroidRuntime(9726):	at java.lang.reflect.Constructor.constructNative(Native Method)
01-10 09:54:38.141: E/AndroidRuntime(9726):	at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
01-10 09:54:38.141: E/AndroidRuntime(9726):	at android.view.LayoutInflater.createView(LayoutInflater.java:500)
01-10 09:54:38.141: E/AndroidRuntime(9726):	... 23 more
01-10 09:54:38.141: E/AndroidRuntime(9726): Caused by: java.lang.IllegalStateException: You are only allowed to have a single MapView in a MapActivity
01-10 09:54:38.141: E/AndroidRuntime(9726):	at com.google.android.maps.MapActivity.setupMapView(MapActivity.java:379)
01-10 09:54:38.141: E/AndroidRuntime(9726):	at com.google.android.maps.MapView.(MapView.java:280)
01-10 09:54:38.141: E/AndroidRuntime(9726):	at com.google.android.maps.MapView.(MapView.java:255)
01-10 09:54:38.141: E/AndroidRuntime(9726):	... 27 more

Following are the code snapshot on how the things are build

MapFragment -> onCreateView()
....
view = inflater.inflate(R.layout.map_page_layout, container, false);
mapView = (MapView) view.findViewById(R.id.mapview);
....

MapFragment Layout File -> map_page_layout
.....

android:layout_alignParentTop="true"
android:clickable="true"/>
.....

InformationFragment -> BackButton ->

Button backButton = (Button) v.findViewById(R.id.backButton);
backButton.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
getActivity().onBackPressed();

}});

Can you please let me know if I am missing something or is it a bug...
Its urgent as I have to meet the deadlines

Thank you
Nikhil