使用com.google.android.gms.maps.MapFragment的另一个片段复制id 0x7f0a00b4,标记null或父ID 0xffffffff

时间:2015-02-24 07:18:27

标签: android android-fragments

  • 我有导航活动,当我开始回家时,它会保存不同的碎片    片段包含两个(乘客和司机)更多的碎片    在它内部,他们正在完美地工作......在乘客时    片段我从我执行的这个片段开始一个活动    一些后台任务,如果它成功执行然后片段也    工作正常,但如果某种方式后台任务失败,那么    活动崩溃,当我回到那个(乘客)片段时    也会因以下异常而崩溃

 java.lang.NullPointerException
        at com.gol.apps.flickcar.NearByPlaces$ParserTask.onPostExecute(NearByPlaces.java:327)
        at com.gol.apps.flickcar.NearByPlaces$ParserTask.onPostExecute(NearByPlaces.java:299)
        at android.os.AsyncTask.finish(AsyncTask.java:631)
        at android.os.AsyncTask.access$600(AsyncTask.java:177)
        at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
        at android.os.Handler.dispatchMessage(Handler.java:107)
        at android.os.Looper.loop(Looper.java:194)
        at android.app.ActivityThread.main(ActivityThread.java:5455)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:525)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:966)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:733)
        at dalvik.system.NativeStart.main(Native Method)



EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gol.apps.flickcar/com.gol.apps.flickcar.NavigationActivity}: android.view.InflateException: Binary XML file line #44: Error inflating class fragment
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2364)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2416)
            at android.app.ActivityThread.access$600(ActivityThread.java:166)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1379)
            at android.os.Handler.dispatchMessage(Handler.java:107)
            at android.os.Looper.loop(Looper.java:194)
            at android.app.ActivityThread.main(ActivityThread.java:5455)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:966)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:733)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.view.InflateException: Binary XML file line #44: Error inflating class fragment
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
            at com.gol.apps.flickcar.fragments.PassengerFragment.onCreateView(PassengerFragment.java:176)
            at android.app.Fragment.performCreateView(Fragment.java:1701)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:885)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1057)
            at android.app.BackStackRecord.run(BackStackRecord.java:694)
            at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1435)
            at android.app.Activity.performStart(Activity.java:5220)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2337)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2416)
            at android.app.ActivityThread.access$600(ActivityThread.java:166)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1379)
            at android.os.Handler.dispatchMessage(Handler.java:107)
            at android.os.Looper.loop(Looper.java:194)
            at android.app.ActivityThread.main(ActivityThread.java:5455)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:966)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:733)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.IllegalArgumentException: Binary XML file line #44: Duplicate id 0x7f0a00b4, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.MapFragment
            at android.app.Activity.onCreateView(Activity.java:4829)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
            at com.gol.apps.flickcar.fragments.PassengerFragment.onCreateView(PassengerFragment.java:176)
            at android.app.Fragment.performCreateView(Fragment.java:1701)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:885)
            at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1057)
            at android.app.BackStackRecord.run(BackStackRecord.java:694)
            at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1435)
            at android.app.Activity.performStart(Activity.java:5220)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2337)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2416)
            at android.app.ActivityThread.access$600(ActivityThread.java:166)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1379)
            at android.os.Handler.dispatchMessage(Handler.java:107)
            at android.os.Looper.loop(Looper.java:194)
            at android.app.ActivityThread.main(ActivityThread.java:5455)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:525)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:966)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:733)
            at dalvik.system.NativeStart.main(Native Method)

这是我的passanger片段的xml布局

<fragment
      android:id="@+id/mapPassenger"
      class="com.google.android.gms.maps.MapFragment"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:layout="@layout/fragment_map" />
  • 我对片段完全陌生..我也搜索了很多但是 我无法解决我的问题请帮助我谢谢

2 个答案:

答案 0 :(得分:1)

你是否试图在fragment_layout中填充片段?

注意:当布局包含<fragment>时,您无法将布局扩展为片段。只有动态添加到片段时才支持嵌套片段。

请参阅此post

答案 1 :(得分:0)

简单回答! 你检查视图是否已经在片段中创建然后返回其他像这样添加

GoogleMap fragmentMap;

if(fragmentMap==null)

     fragmentMap = ((com.google.android.gms.maps.MapFragment) getActivity().getFragmentManager().
     findFragmentById(R.id.mapfragment)).getMap();