Squareup Picasso.with() method unresolved Android Studio

做~自己de王妃 提交于 2019-12-12 15:40:23

问题


I'm developing an Android App for practice that uses a Weather API and presents current weather data on screen. It's supposed to use Picasso to present the weather icon for the current weather state on an ImageView element. However, Android Studio cannot resolve the .with() method although it recognises Picasso. I added Picasso to my dependencies and I also added the import for Picasso in the class.

Screenshot of the code section - .with() in red beacuse it's unresolved

I won't add the code for the whole class because it's kind of big and can get confusing so here is the whole code for the function where I'm referencing Picasso:

@Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
        if(s.contains("Error: Not found city")){
            pd.dismiss();
            return;
        }
        Gson gson = new Gson();
        Type mType = new TypeToken<OpenWeatherMap>(){}.getType();
        openWeatherMap = gson.fromJson(s, mType);
        pd.dismiss();

        txtCity.setText(String.format("%s,%s", openWeatherMap.getName(),openWeatherMap.getSys().getCountry()));

        txtLastUpdate.setText(String.format("Last Updated: %s", Common.getDateNow()));

        txtDescription.setText(String.format("%s", openWeatherMap.getWeatherList().get(0).getDescription()));

        txtHumidity.setText(String.format("%d%%", openWeatherMap.getMain().getHumidity()));

        txtTime.setText(String.format("%s/%s", Common.unixTimeStampToDateTime(openWeatherMap.getSys().getSunrise()), Common.unixTimeStampToDateTime(openWeatherMap.getSys().getSunset())));

        txtCelsius.setText(String.format("%.2f °C", openWeatherMap.getMain().getTemp()));

        Picasso.with(MainActivity.this)
                .load(Common.getImage(openWeatherMap.getWeatherList().get(0).getIcon()))
                .into(imageView);

    }

I'm using Android Studio V3.0.1, Android API 26 and Picasso V2.71828. Thanks in advance. Cheers!


回答1:


use like this :

Picasso.get().load(Common.getImage(openWeatherMap.getWeatherList().get(0).getIcon()))
                        .into(imageView);


来源:https://stackoverflow.com/questions/49206039/squareup-picasso-with-method-unresolved-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!