Я использую AsyncTask для получения своих результатов. Я получаю сообщение об ошибке в методе doinbackground, в котором говорится, что он пытается вызвать метод для нулевой ссылки на объект.
Вот мой код, частный класс PlaceListTask расширяет AsyncTask > {
private String strAddress;
public PlaceListTask(String strAddress) {
super();
this.strAddress = strAddress;
}
public String getStrAddress() {
return strAddress;
}
public void setStrAddress(String strAddress) {
this.strAddress = strAddress;
}
@Override
protected ArrayList<AutocompletePrediction> doInBackground(String... params) {
List<Place.Field> placeFields = Arrays.asList(Place.Field.ID, Place.Field.NAME /* add more Place.Field. fields as you need*/);
FindCurrentPlaceRequest request =
FindCurrentPlaceRequest.newInstance(placeFields);
Task<FindCurrentPlaceResponse> placeResponse = placesClient.findCurrentPlace(request);
placeResponse.addOnCompleteListener(task -> {
if (task.isSuccessful()) {
FindCurrentPlaceResponse response = task.getResult();
for (PlaceLikelihood placeLikelihood : response.getPlaceLikelihoods()) {
Log.i(TAG, String.format("Place '%s' has likelihood: %f",
placeLikelihood.getPlace().getName(),
placeLikelihood.getLikelihood()));
}
} else {
Exception exception = task.getException();
if (exception instanceof ApiException) {
ApiException apiException = (ApiException) exception;
Log.e(TAG, "Place not found: " + apiException.getStatusCode());
}
}
});
return null;
}
Это ошибка, которую я получаю Попытка вызвать метод интерфейса 'com.google. android .gms.tasks.Task com.google. android .libraries.places.api. net .PlacesClient.findCurrentPlace (com.google. android .libraries.places.api. net .FindCurrentPlaceRequest) 'для ссылки на пустой объект