Reputation: 339
I'm using Google Places API, and I need to retrieve Place Details using Place ID. I'm trying to invoke method getPlaceById()
, but it always fails. Here's the log:
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)
My code:
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();
});
}
It's quite strange, because Google Places API has been connected properly. What could be possible reason of this exception?
Upvotes: 2
Views: 1749
Reputation: 946
If you want to continue using the object contained in the buffer after you've released the buffer, call freeze()
on the object before calling release()
You can use
isDataValid()
at any time to determine if the object is available or not. For example,place.isDataValid()
returns true before the call tobuffer.release()
and false afterwards. Note thatfrozen.isDataValid()
returns true both before and after the buffer has been released.
Reference https://developers.google.com/places/android-api/buffers
Upvotes: 11
Reputation: 749
A good way to start is by Logging what's going on. You can validate if the result of the operation was successful by refactoring your if-statement like this:
if (places.getStatus().isSuccess() && places.getCount() > 0)
Check the message of the status for further information:
String msg = places.getStatus().getStatusMessage();
Log.e(<some TAG>, "Status message: " + msg);
Then simply check the LogCat for the status message. That's not a real answer but it would definitely give you some clues on how to proceed.
Upvotes: 2