我有以下问题: 我有两个片段一个FragmentActivity。在其中一人有一个MapFragment。如果我打开片段与地图第一次一切都运行完美。但是,当我浏览回第一个片段,然后打开与地图的片段重新应用程序崩溃与以下LogCat中输出:
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
我的片段与地图:
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;
}
}
我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"/>
我的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?
如果您使用的是 FragmentActivity
,这意味着你使用的是碎片的支持Android包的反向移植。在这种情况下,你需要使用 SupportMapFragment
,不是 MapFragment
,在你的布局。
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.
上一篇:Android摄像头preVIEW放大使用双指触控摄像头、触控、Android、preVIEW
下一篇:未能提供结果ResultInfo {谁= NULL,请求= 0,结果= -1,数据= NULL}到活动结果、数据、ResultInfo、NULL