4

I am having a bit if trouble with my Google Maps application. I have three buttons in my application; "Open Google Maps", "Camera" and "Touch". When the application lanuches it goes straight to the Google Maps screen, everything works fine up until this point but when the user is on Google Maps screen and clicks Google Maps button again, the application crashes and I get the following errors in my logcat;

02-28 11:39:25.844: E/AndroidRuntime(2782): FATAL EXCEPTION: main
02-28 11:39:25.844: E/AndroidRuntime(2782): Process: com.GoogleMapsapplication.main, PID: 2782
02-28 11:39:25.844: E/AndroidRuntime(2782): android.view.InflateException: Binary XML file line #33: Error inflating class fragment
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at com.augmentedthorpepark.main.FragmentGoogleMap.onCreateView(GoogleMapsFragment.java:50)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.app.Fragment.performCreateView(Fragment.java:1700)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:890)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.app.BackStackRecord.run(BackStackRecord.java:684)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.app.FragmentManagerImpl$1.run(FragmentManager.java:443)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.os.Handler.handleCallback(Handler.java:733)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.os.Handler.dispatchMessage(Handler.java:95)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.os.Looper.loop(Looper.java:136)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.app.ActivityThread.main(ActivityThread.java:5146)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at java.lang.reflect.Method.invokeNative(Native Method)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at java.lang.reflect.Method.invoke(Method.java:515)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at dalvik.system.NativeStart.main(Native Method)
02-28 11:39:25.844: E/AndroidRuntime(2782): Caused by: java.lang.IllegalArgumentException: Binary XML file line #33: Duplicate id 0x7f090035, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
02-28 11:39:25.844: E/AndroidRuntime(2782):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)

it says that I have error in my xml file at line #33 but from my experience and what I found from my search online, this is how I am suppose to use Google Maps;

My xml file with the Google Map code;

<fragment
    android:id="@+id/googlemap"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment" />

Also, I am working with fragments. So I am unable to extend Activity, FragmentActivity etc.

public class GoogleMapsFragment extends Fragment {
 .....
}

Is there any way I can fix this bug, thanks.

3
  • You already have a fragment (extends Fragment) and then in your xml you have a fragment. That's why the Duplicate id 0x7f090035, tag null, or parent id 0x0 with another fragment for com.google.android.gms.maps.SupportMapFragment. Check this stackoverflow.com/questions/20919048/… Commented Feb 28, 2015 at 12:00
  • Hi Rghunandan I have already been on that post and tried making mapView but I still get the same error but I will give it another try. Commented Feb 28, 2015 at 12:03
  • you might be doing it wrong. that post should help Commented Feb 28, 2015 at 12:06

1 Answer 1

1

Based on your logcat output, it seems that you are adding the same Fragment twice. This leads to either an IllegalStateException or an IllegalArgumentException.

The solution is to check which Fragment is currently in the foreground first and avoid adding the same one if it is already present:

Fragment f = (Fragment)getFragmentManager().findFragmentByTag("xyz_fragment");
if (f!=null && !f.isVisible() && !f.isAdded()) {

    ....

}
Sign up to request clarification or add additional context in comments.

10 Comments

Do I remove the FragmentManager.remove() on Destroy?
I get this error on .remove - The method remove() is undefined for the type FragmentManager
@Mikey: apologies, I was thinking of FragmentTransaction.replace(). Please see edited answer
Thanks Zygotelnit, I will try it now. For xyz_fragment, do I need to put reference to my google maps? e.g. Fragment f = (Fragment)getFragmentManager().findFragmentByTag("googlemap");
That depends on how you have added the Fragment ... if you used FragmentTransaction.add() method with a tag "googlemap", then yes, you can certainly use Fragment f = (Fragment)getFragmentManager().findFragmentByTag("googlemap");.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.