Squareup Picasso.with() method unresolved Android

2019-07-22 08:35发布

问题:

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);