放置自动完成片段-二进制XML文件第19行:膨胀类片段的错误

时间:2019-03-29 09:18:30

标签: java android

我有一个具有recyclerview的布局,在其中我为cardview布局充气。当我在卡片中添加自动完成片段的位置时,应用程序会崩溃。 我希望每张卡都有片段

卡片视图的代码

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:layout_marginTop="20dp"
>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="8dp">

     <fragment
         android:id="@+id/place_autocomplete_fragment"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_gravity="center"
         android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment" />

    <android.support.design.button.MaterialButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/add_place"
        android:layout_marginTop="10dp"
        android:padding="10dp"
        android:textStyle="bold"
        android:background="@color/colorPrimary"

        />

</LinearLayout>
</android.support.v7.widget.CardView>

这是错误日志。我尝试将片段直接添加到recyclerview上方,并且可以正常工作。但我希望每张卡都有它。

E/AndroidRuntime: FATAL EXCEPTION: main
              Process: com.example.nehemiah.employertracker, PID: 15338
              android.view.InflateException: Binary XML file line #61: Binary XML file line #61: Error inflating class fragment
              Caused by: android.view.InflateException: Binary XML file line #61: Error inflating class fragment
              Caused by: java.lang.IllegalArgumentException: Binary XML file line #61: Duplicate id 0x7f08008e, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.location.places.ui.PlaceAutocompleteFragment
                  at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3541)
                  at android.app.FragmentController.onCreateView(FragmentController.java:98)
                  at android.app.Activity.onCreateView(Activity.java:6240)
                  at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:389)
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
                  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
                  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
                  at android.view.LayoutInflater.rInflate(LayoutInflater.java:866)
                  at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
                  at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
                  at com.example.nehemiah.employertracker.Admin.EmployeeAdapter.onCreateViewHolder(EmployeeAdapter.java:38)
                  at com.example.nehemiah.employertracker.Admin.EmployeeAdapter.onCreateViewHolder(EmployeeAdapter.java:20)
                  at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6794)
                  at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5975)
                  at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858)
                  at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5854)
                  at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2230)
                  at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1557)
                  at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1517)
                  at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:612)
                  at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3924)
                  at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:3641)
                  at android.support.v7.widget.RecyclerView.consumePendingUpdateOperations(RecyclerView.java:1888)
                  at android.support.v7.widget.RecyclerView$1.run(RecyclerView.java:407)
                  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:924)
                  at android.view.Choreographer.doCallbacks(Choreographer.java:732)
                  at android.view.Choreographer.doFrame(Choreographer.java:661)
                  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:910)
                  at android.os.Handler.handleCallback(Handler.java:790)
                  at android.os.Handler.dispatchMessage(Handler.java:99)
                  at android.os.Looper.loop(Looper.java:164)
                  at android.app.ActivityThread.main(ActivityThread.java:6524)
                  at java.lang.reflect.Method.invoke(Native Method)
                  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
                  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:888)

1 个答案:

答案 0 :(得分:0)

只需输入:

 inParams["sValueName"] = "DisplayName";
            // Read Registry Value
            outParams = registry.InvokeMethod("GetStringValue", inParams, null);
            if (outParams.Properties["sValue"].Value != null)
            {
               Console.WriteLine($"Value: {outParams.Properties["sValue"].Value.ToString()}");
            }

            inParams["sValueName"] = "InstallDate";
            // Read Registry Value 
            outParams = registry.InvokeMethod("GetStringValue", inParams, null);
            if (outParams.Properties["sValue"].Value != null)
            {
                Console.WriteLine($"Value: {outParams.Properties["sValue"].Value.ToString()}");
            }

确保您已添加此Gradle

实现'com.google.android.gms:play-services-places:16.0.0'