我正在尝试使用具有某些Mapbox功能的AutoCompleteFragment作为android文档的地方插件说,但我有一个例外,我真的不知道发生了什么...我只知道例外是:< / p>
android.view.InflateException: Binary XML file line #22: Binary XML file line #22: Error inflating class com.mapbox.mapboxsdk.plugins.places.autocomplete.ui.SearchView
Caused by: android.view.InflateException: Binary XML file line #22: Error inflating class com.mapbox.mapboxsdk.plugins.places.autocomplete.ui.SearchView
Caused by: java.lang.reflect.InvocationTargetException
xml文件的一部分:
<androidx.cardview.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="23dp"
card_view:cardCornerRadius="4dp"
card_view:layout_constraintBottom_toTopOf="@+id/textView2"
card_view:layout_constraintEnd_toEndOf="parent"
card_view:layout_constraintHorizontal_bias="0.47"
card_view:layout_constraintStart_toStartOf="parent">
<fragment
android:id="@+id/autocomplete_fragment"
android:name="com.google.android.libraries.places.widget.AutocompleteSupportFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="@layout/places_autocomplete_fragment" />
</androidx.cardview.widget.CardView>
设置onPlaceSelectionListener:
PlaceAutocompleteFragment autocompleteFragment;
if (savedInstanceState == null) {
autocompleteFragment = PlaceAutocompleteFragment.newInstance("Example Token That Isn't in the code");
final FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.add(R.id.autocomplete_fragment, autocompleteFragment,TAG);
transaction.commit();
} else {
autocompleteFragment = (PlaceAutocompleteFragment)
getSupportFragmentManager().findFragmentById(R.id.autocomplete_fragment);
}
autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {
@Override
public void onPlaceSelected(CarmenFeature carmenFeature) {
Geometry geometry = carmenFeature.geometry();
Toast.makeText(MainActivity.this, carmenFeature.text(), Toast.LENGTH_SHORT).show();
}
@Override
public void onCancel() {
}
});
我只是尝试运行该应用