如何解决无法实例化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 举报,一经查实,本站将立刻删除。