Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 被列表和改装2和foreach卡住了_Java_List_Foreach_Retrofit2 - Fatal编程技术网

Java 被列表和改装2和foreach卡住了

Java 被列表和改装2和foreach卡住了,java,list,foreach,retrofit2,Java,List,Foreach,Retrofit2,我正在尝试使用从1.9.0升级到2.1.0的改进,因为我无法运行我想放在地图上的标记。 在改造1.9.0时,它工作得非常完美,但希望使用更新的系统 Retrofit adapter = new Retrofit.Builder() .baseUrl( AppConfig.URL_PINS ) .addConverterFactory(GsonConverterFactory.create()) .bu

我正在尝试使用从1.9.0升级到2.1.0的改进,因为我无法运行我想放在地图上的标记。 在改造1.9.0时,它工作得非常完美,但希望使用更新的系统

Retrofit adapter = new Retrofit.Builder()
                .baseUrl( AppConfig.URL_PINS )
                .addConverterFactory(GsonConverterFactory.create())
                .build();

MapPinsApiInterface pinsApiInterface = adapter.create(MapPinsApiInterface.class);
Call<List<MapPins>> pins = (Call<List<MapPins>>) pinsApiInterface.getStreams();
pins.enqueue(new Callback<List<MapPins>>() {
    @Override
    public void onResponse(Call<List<MapPins>> pins, Response<List<MapPins>> response) {
        if (!isAdded() || pins == null )
            return;

        int numMarkersInRainbow[] = {
            R.mipmap.homecenter,
            R.mipmap.shop,
            R.mipmap.marksilv,
            R.mipmap.markgold,
            R.mipmap.markgreen,
            R.mipmap.markoran,
            R.mipmap.itsyou,
            R.mipmap.no_gps
        };
        bounds = new LatLngBounds.Builder();

        for (MapPins pin : pins) {    <***** Here is my error ***>
            MarkerOptions options = new MarkerOptions().position(new LatLng(pin.getLatitude(), pin.getLongitude()));
            options.title(pin.getName());
            options.snippet(pin.getDepth());
            options.icon(BitmapDescriptorFactory.fromResource(numMarkersInRainbow[pin.getMarker()]));

            Marker mkr = googleMap.addMarker(options);
            mMarkers.put(mkr.getId(), pin.getSiteid());
            bounds.include(new LatLng(pin.getLatitude(), pin.getLongitude()));
        }
    }
改装适配器=新改装.Builder()
.baseUrl(AppConfig.URL\u引脚)
.addConverterFactory(GsonConverterFactory.create())
.build();
MapPinsApiInterface pinsApiInterface=适配器.create(MapPinsApiInterface.class);
Call pins=(Call)pinsApiInterface.getStreams();
pins.enqueue(新回调(){
@凌驾
公共void onResponse(呼叫PIN、响应){
如果(!isAdded()| | pins==null)
返回;
int numMarkersInRainbow[]={
R.mipmap.homecenter,
R.mipmap.shop,
R.mipmap.marksilv,
R.mipmap.markgold,
R.mipmap.markgreen,
R.mipmap.markoran,
R.mipmap.Itsue,
R.mipmap.no\u全球定位系统
};
bounds=新的LatLngBounds.Builder();
对于(MapPins:pins){
MarkerOptions options=newmarkeroptions().position(新车床(pin.getLatitude(),pin.getLongitude());
options.title(pin.getName());
options.snippet(pin.getDepth());
图标(BitmapDescriptorFactory.fromResource(numMarkersInRainbow[pin.getMarker()]);
Marker mkr=googleMap.addMarker(选项);
mMarkers.put(mkr.getId(),pin.getSiteid());
包括(新的LatLng(pin.getLatitude(),pin.getLongitude());
}
}
行中:
(MapPins:pins){

我犯了一个错误

对于不适用于“改装2.调用”类型的每个


我确信我忽略了什么。我缺少什么?

您需要使用您获得的
2.Response
实例,从中您可以获得
列表:

但您还应检查以下各项:


您需要使用您获得的
2.Response
实例,从中可以获得
列表

但您还应检查以下各项:

for (MapPins pin : response.body()) {
    // ...
}
if (!response.isSuccessful()) {
    // handle
}