无法实例化PlaceAutocomplete

问题描述

我在Google地方信息自动填充方面遇到问题,遇到以下错误,并且不确定如何解决此问题:

2020-09-21 11:33:02.894 29037-29037/com.example.hostapp E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.hostapp,PID: 29037
    android.view.InflateException: Binary XML file line #18: Binary XML file line #18: Error inflating class fragment
    Caused by: android.view.InflateException: Binary XML file line #18: Error inflating class fragment
    Caused by: android.app.Fragment$InstantiationException: Trying to instantiate a class com.google.android.gms.location.places.ui.PlaceAutocomplete that is not a Fragment

这是XML

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_margin="5dp"
    app:cardElevation="5dp"
    app:cardCornerRadius="5dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:layout_margin="5dp"
        android:padding="10dp">

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

    </LinearLayout>


</androidx.cardview.widget.CardView>

这是我在我的代码中调用自动完成的地方:

final PlaceAutocompleteFragment mUseraddress = (PlaceAutocompleteFragment)getFragmentManager().findFragmentById(R.id.places_autocomplete_fragment);
               //HIDE SEARCH ICON BEFORE FRAGMENT
               mUseraddress.getView().findViewById(R.id.place_autocomplete_search_button).setVisibility(View.GONE);
               //set hint for address
               ((EditText)mUseraddress.getView().findViewById(R.id.place_autocomplete_search_input))
                       .setHint("Delivery Address");
               //set font size for address
               ((EditText)mUseraddress.getView().findViewById(R.id.place_autocomplete_search_input))
                       .setTextSize(14);

               //GET ADDRESS
               mUseraddress.setOnPlaceSelectedListener(new PlaceSelectionListener() {
                   @Override
                   public void onPlaceSelected(Place place) {
                    deliveryAddress = place;
                   }

                   @Override
                   public void onError(Status status) {
Log.e("ERROR",status.getStatusMessage());
                   }
               });

最后,我已经在Gradle中实现了。

// Google服务 实施'com.google.android.gms:play-services-places:11.6.2'

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...