我使用的是旧版SDK,但效果不错,但是将要折旧,因此我改用新版SDK.我得到了一些设备的崩溃报告.

崩溃报告:

Fatal Exception: java.lang.RuntimeException

Unable to start activity ComponentInfo{com.islamuna.ramadan/com.google.android.libraries.places.widget.AutocompleteActivity}: java.lang.IllegalStateException: Places must be initialized.

SDK版本:

implementation 'com.google.android.libraries.places:places:1.1.0'

甚至我初始化Place示例代码:

Places.initialize(getApplicationContext(), "mykey", Locale.US);

autocompleteFragment = (AutocompleteSupportFragment)

getSupportFragmentManager().findFragmentById(R.id.place_autocomplete_fragment);

autocompleteFragment.setPlaceFields(Arrays.asList(Place.Field.ID, Place.Field.NAME,Place.Field.LAT_LNG));

autocompleteFragment.setText(Global.getStoredStringValue(getApplicationContext(), getString(R.string.KEY_CITY)));

autocompleteFragment.setOnPlaceSelectedListener(new PlaceSelectionListener() {

@Override

public void onPlaceSelected(Place place) {

try {

}

} catch (Exception e) {

}

}

@Override

public void onError(Status status) {

// TODO: Handle the error.

}

});

布局XML

android:id="@+id/place_autocomplete_fragment"

android:name="com.google.android.libraries.places.widget.AutocompleteSupportFragment"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@drawable/border_filled" />

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐