Reputation: 775
I have the following problem:
I have a FragmentActivity with two fragments. In one of them there's a MapFragment. If I open the Fragment with the map the first time all is running perfectly. But when I navigate back to the first Fragment and then open the Fragment with the map again the app crashes with the following LogCat output:
02-02 17:01:28.589: E/AndroidRuntime(13587): FATAL EXCEPTION: main
02-02 17:01:28.589: E/AndroidRuntime(13587): Process: de.simeon.maps, PID: 13587
02-02 17:01:28.589: E/AndroidRuntime(13587): android.view.InflateException: Binary XML file line #1: Error inflating class fragment
02-02 17:01:28.589: E/AndroidRuntime(13587): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
02-02 17:01:28.589: E/AndroidRuntime(13587): at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
02-02 17:01:28.589: E/AndroidRuntime(13587): at de.robv.android.xposed.XposedBridge.invokeOriginalMethodNative(Native Method)
02-02 17:01:28.589: E/AndroidRuntime(13587): at de.robv.android.xposed.XposedBridge.handleHookedMethod(XposedBridge.java:547)
02-02 17:01:28.589: E/AndroidRuntime(13587): at android.view.LayoutInflater.inflate(Native Method)
02-02 17:01:28.589: E/AndroidRuntime(13587): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
02-02 17:01:28.589: E/AndroidRuntime(13587): at de.simeon.maps.MainActivity$Map.onCreateView(MainActivity.java:141)
02-02 17:01:28.589: E/AndroidRuntime(13587): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
02-02 17:01:28.589: E/AndroidRuntime(13587): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
02-02 17:01:28.589: E/AndroidRuntime(13587): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
02-02 17:01:28.589: E/AndroidRuntime(13587): at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
02-02 17:01:28.589: E/AndroidRuntime(13587): at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1467)
02-02 17:01:28.589: E/AndroidRuntime(13587): at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:440)
02-02 17:01:28.589: E/AndroidRuntime(13587): at android.os.Handler.handleCallback(Handler.java:733)
02-02 17:01:28.589: E/AndroidRuntime(13587): at android.os.Handler.dispatchMessage(Handler.java:95)
02-02 17:01:28.589: E/AndroidRuntime(13587): at android.os.Looper.loop(Looper.java:136)
02-02 17:01:28.589: E/AndroidRuntime(13587): at android.app.ActivityThread.main(ActivityThread.java:5017)
02-02 17:01:28.589: E/AndroidRuntime(13587): at java.lang.reflect.Method.invokeNative(Native Method)
02-02 17:01:28.589: E/AndroidRuntime(13587): at java.lang.reflect.Method.invoke(Method.java:515)
02-02 17:01:28.589: E/AndroidRuntime(13587): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-02 17:01:28.589: E/AndroidRuntime(13587): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-02 17:01:28.589: E/AndroidRuntime(13587): at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:126)
02-02 17:01:28.589: E/AndroidRuntime(13587): at dalvik.system.NativeStart.main(Native Method)
02-02 17:01:28.589: E/AndroidRuntime(13587): Caused by: java.lang.IllegalArgumentException: Binary XML file line #1: Duplicate id 0x7f050006, tag null, or parent id 0x7f050005 with another fragment for com.google.android.gms.maps.MapFragment
02-02 17:01:28.589: E/AndroidRuntime(13587): at android.app.Activity.onCreateView(Activity.java:4791)
02-02 17:01:28.589: E/AndroidRuntime(13587): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
02-02 17:01:28.589: E/AndroidRuntime(13587): ... 22 more
My Fragment with the map:
public static class Map extends Fragment {
public Map() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_map, container, false);
return rootView;
}
}
My fragment_map.xml:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"
tools:context=".MainActivity$Map"
tools:ignore="MergeRootFrame"/>
My AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.simeon.maps"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="example.gps.permission.MAPS_RECEIVE"
android:protectionLevel="signature"></permission>
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyD6KQk5r39QnU_M5JOJwA3klu7jsXMD7Jk" />
<activity
android:name="de.simeon.maps.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Could you please help me?
Upvotes: 1
Views: 6841
Reputation: 158
API key must be specified only in google_maps_api.xml. In the manifest meta-data tag, just put the value of the key as resource string @string/google_maps_key.
Hope it helps..!
Upvotes: 0
Reputation: 1007534
If you are using FragmentActivity
, that means that you are using the Android Support package's backport of fragments. In that case, you need to use SupportMapFragment
, not MapFragment
, in your layout.
Also note that you are attempting to put a fragment inside a fragment. While this is possible, it is unlikely to be what you want.
Upvotes: 4