getPlaceByID()始终因java.lang.IllegalArgumentException而失败:缓冲区已关闭

hor*_*319 3 android google-places-api

我正在使用Google Places API,我需要使用地方ID检索地方详情.我正在尝试调用方法getPlaceById(),但它总是失败.这是日志:

java.lang.IllegalArgumentException: Buffer is closed.
at com.google.android.gms.common.data.DataHolder.zzg(Unknown Source)
at com.google.android.gms.common.data.DataHolder.zzi(Unknown Source)
at com.google.android.gms.common.data.zzc.zzcB(Unknown Source)
at com.google.android.gms.location.places.internal.zzt.zzG(Unknown Source)
at com.google.android.gms.location.places.internal.zzb.getPlaceId(Unknown Source)
at .onPredictionSelected(CreateLocationActivity.java:181)
at .AutocompletePredictionsHelper.onItemClick(AutocompletePredictionsHelper.java:51)
at android.widget.AutoCompleteTextView.performCompletion(AutoCompleteTextView.java:905)
at android.widget.AutoCompleteTextView.access$400(AutoCompleteTextView.java:90)
at android.widget.AutoCompleteTextView$DropDownItemClickListener.onItemClick(AutoCompleteTextView.java:1195)
at android.widget.AdapterView.performItemClick(AdapterView.java:300)
at android.widget.AbsListView.performItemClick(AbsListView.java:1247)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3215)
at android.widget.AbsListView$3.run(AbsListView.java:4009)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:155)
at android.app.ActivityThread.main(ActivityThread.java:5696)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1028)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
Run Code Online (Sandbox Code Playgroud)

我的代码:

public void onPredictionSelected(AutocompletePrediction prediction) {
    if (!googleApiClient.isConnected()) return;
    PendingResult<PlaceBuffer> result =
            Places.GeoDataApi.getPlaceById(googleApiClient, prediction.getPlaceId());
    result.setResultCallback(places -> {
        if (places.getCount() > 0)
            place = places.get(0);
        places.release();
    });
}
Run Code Online (Sandbox Code Playgroud)

这很奇怪,因为Google Places API已正确连接.这种例外可能的原因是什么?

new*_*use 11

如果要在释放缓冲区后继续使用缓冲区中包含的对象,请freeze()在调用之前调用该对象release()

您可以随时使用isDataValid()以确定对象是否可用.例如,place.isDataValid()在调用之前返回true ,之后返回buffer.release()false.请注意,frozen.isDataValid()在缓冲区释放之前和之后都返回true.

参考 https://developers.google.com/places/android-api/buffers