Places auto complete fragment-Binary XML file line #19: Error inflating class fragment

2

I have a layout having a recyclerview in which i inflate a cardview layout.when i add places auto complete fragment in the card,the app crushes. i want each card to a have the fragment

the code for the 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>

This is the error log.i tried adding the fragment directly above the recyclerview and it worked. but i want each card to have it.

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)
java
android
asked on Stack Overflow Mar 29, 2019 by K.Nehe • edited Mar 29, 2019 by K.Nehe

1 Answer

0

Just put this:

<?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_marginTop="20dp"
    android:layout_marginEnd="8dp">

    <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:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </LinearLayout>
</android.support.v7.widget.CardView>

make sure you have added this gradle

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

answered on Stack Overflow Mar 29, 2019 by Haresh Ramani

User contributions licensed under CC BY-SA 3.0