繁体   English   中英

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

[英]Error:Execution failed for task ':app:transformClassesWithDexForDebug'. > com.android.build.api.transform.TransformException:

 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 '片段Unchecked call to ' add(E) ' as a member of raw type java.util.ArrayList该片段' as a member of raw type java.util.ArrayList

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

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

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

另请参见: 使用向量的Java警告:未选中的add(E)调用

转到Build-> Clean Project现在重新运行代码。 它会工作。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM