使用com.google.android.gms.maps.SupportMapFragment的另一个片段复制id,tag null或parent id

时间:2017-04-29 03:59:14

标签: android google-maps android-fragments

我想创建一个图片滑块,但我收到此错误。

错误行是:

 layoutInflater = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        **View item_view = layoutInflater.inflate(R.layout.vendor_details_page, container,false);**
    ImageView imageView = (ImageView)item_view.findViewById(R.id.vendor_image);
    imageView.setImageResource(image_resources[position]);
    container.addView(item_view);
    return item_view;

04-29 09:25:45.857 16366-16366/com.example.binarystore.project1 E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.example.binarystore.project1, PID: 16366
  android.view.InflateException: Binary XML file line #302: Error inflating class fragment
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
      at com.example.binarystore.project1.vendor_details.CustomSwipeAdaptor.instantiateItem(CustomSwipeAdaptor.java:42)
      at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:1034)
      at android.support.v4.view.ViewPager.populate(ViewPager.java:1182)
      at android.support.v4.view.ViewPager.populate(ViewPager.java:1116)
      at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1642)
      at android.view.View.measure(View.java:16834)
      at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:824)
      at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:500)
      at android.view.View.measure(View.java:16834)
      at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5379)
      at android.widget.FrameLayout.onMeasure(FrameLayout.java:340)
      at android.view.View.measure(View.java:16834)
      at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5379)
      at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1621)
      at android.widget.LinearLayout.measureVertical(LinearLayout.java:742)
      at android.widget.LinearLayout.onMeasure(LinearLayout.java:607)
      at android.view.View.measure(View.java:16834)
      at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5379)
      at android.widget.FrameLayout.onMeasure(FrameLayout.java:340)
      at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2368)
      at android.view.View.measure(View.java:16834)
      at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2246)
      at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1312)
      at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1509)
      at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1189)
      at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6223)
      at android.view.Choreographer$CallbackRecord.run(Choreographer.java:788)
      at android.view.Choreographer.doCallbacks(Choreographer.java:591)
      at android.view.Choreographer.doFrame(Choreographer.java:560)
      at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:774)
      at android.os.Handler.handleCallback(Handler.java:808)
      at android.os.Handler.dispatchMessage(Handler.java:103)
      at android.os.Looper.loop(Looper.java:193)
      at android.app.ActivityThread.main(ActivityThread.java:5333)
      at java.lang.reflect.Method.invokeNative(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:515)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
      at dalvik.system.NativeStart.main(Native Method)
   Caused by: java.lang.IllegalArgumentException: Binary XML file line #302: Duplicate id 0x7f100186, tag null, or parent id 0x7f100180 with another fragment for com.google.android.gms.maps.SupportMapFragment
      at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3447)
      at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
      at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:378)
      at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:33)
      at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:79)
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:755) 
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:758) 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
      at com.example.binarystore.project1.vendor_details.CustomSwipeAdaptor.instantiateItem(CustomSwipeAdaptor.java:42) 
      at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:1034) 
      at android.support.v4.view.ViewPager.populate(ViewPager.java:1182) 
      at android.support.v4.view.ViewPager.populate(ViewPager.java:1116) 
      at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1642) 
      at android.view.View.measure(View.java:16834) 
      at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:824) 
      at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:500) 
      at android.view.View.measure(View.java:16834) 
      at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5379) 
      at android.widget.FrameLayout.onMeasure(FrameLayout.java:340) 
      at android.view.View.measure(View.java:16834) 
      at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5379) 
      at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1621) 
      at android.widget.LinearLayout.measureVertical(LinearLayout.java:742) 
      at android.widget.LinearLayout.onMeasure(LinearLayout.java:607) 
      at android.view.View.measure(View.java:16834) 
      at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5379) 
      at android.widget.FrameLayout.onMeasure(FrameLayout.java:340) 
      at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2368) 
      at android.view.View.measure(View.java:16834) 
      at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2246) 
      at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1312) 
      at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1509) 
      at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1189) 
      at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6223) 
      at android.view.Choreographer$CallbackRecord.run(Choreographer.java:788) 
      at android.view.Choreographer.doCallbacks(Choreographer.java:591) 
      at android.view.Choreographer.doFrame(Choreographer.java:560) 
      at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:774) 
      at android.os.Handler.handleCallback(Handler.java:808) 
      at android.os.Handler.dispatchMessage(Handler.java:103) 
      at android.os.Looper.loop(Looper.java:193) 
      at android.app.ActivityThread.main(ActivityThread.java:5333) 
      at java.lang.reflect.Method.invokeNative(Native Method) 
      at java.lang.reflect.Method.invoke(Method.java:515) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645) 
      at dalvik.system.NativeStart.main(Native Method) 

1 个答案:

答案 0 :(得分:0)

确保Activity扩展AppCompatActivity appcompat-v7支持库中的内容。

另请确保使用android.support.v4.app.Fragment代替android.app.Fragment

最后,确认getSupportFragmentManager()代替getFragmentManager()