Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting java.lang.IllegalStateException: You are only allowed to have a single MapView in a MapActivity Exception when using MapView for fragments #5

Closed
nikhil4coding opened this issue Jan 10, 2012 · 1 comment

Comments

@nikhil4coding
Copy link

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
.....
<com.google.android.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey=
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

@nikhil4coding
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant