错误:任务':app:transformClassesWithDexForDebug'的执行失败。 > com.android.build.api.transform.TransformException:

时间:2017-03-14 14:32:01

标签: android google-places-api

 private ArrayList<PlaceAutocomplete> getPredictions(CharSequence constraint) {
    if (mGoogleApiClient != null) {
        Log.i(TAG, "Executing autocomplete query for: " + constraint);
        PendingResult<AutocompletePredictionBuffer> results =
                Places.GeoDataApi
                        .getAutocompletePredictions(mGoogleApiClient, constraint.toString(),
                                mBounds, mPlaceFilter);
        // Wait for predictions, set the timeout.
        AutocompletePredictionBuffer autocompletePredictions = results
                .await(60, TimeUnit.SECONDS);
        final Status status = autocompletePredictions.getStatus();
        if (!status.isSuccess()) {
            Toast.makeText(getContext(), "Error: " + status.toString(),
                    Toast.LENGTH_SHORT).show();
            Log.e(TAG, "Error getting place predictions: " + status
                    .toString());
            autocompletePredictions.release();
            return null;
        }

        Log.i(TAG, "Query completed. Received " + autocompletePredictions.getCount()
                + " predictions.");
        Iterator<AutocompletePrediction> iterator = autocompletePredictions.iterator();
        ArrayList resultList = new ArrayList<>(autocompletePredictions.getCount());
        while (iterator.hasNext()) {
            AutocompletePrediction prediction = iterator.next();
            resultList.add(new PlaceAutocomplete(prediction.getPlaceId(),
                    prediction.getFullText(null)));
        }
        // Buffer release
        autocompletePredictions.release();
        return resultList;
    }
    Log.e(TAG, "Google API client is not connected.");
    return null;
}

我将播放服务升级到10.2.0后,我得到一个例外 Unchecked call to '在此片段中添加(E)' as a member of raw type java.util.ArrayList

resultList.add(new PlaceAutocomplete(prediction.getPlaceId(),
                    prediction.getFullText(null)));

2 个答案:

答案 0 :(得分:0)

在声明resultsList时指定类型,如下所示:

ArrayList<PlaceAutocomplete> resultList = new ArrayList<>(autocompletePredictions.getCount());

另请参阅:Java Warning using Vectors: unchecked call to add(E)

答案 1 :(得分:0)

转到 构建 - &gt;清洁项目 现在重新运行代码。它会起作用。