Squareup Picasso.with()方法未解析Android Studio

问题描述 投票:1回答:1

我正在开发一个Android应用程序,用于练习,使用Weather API并在屏幕上显示当前的天气数据。它应该使用Picasso在ImageView元素上显示当前天气状态的天气图标。但是,Android Studio无法解析.with()方法,尽管它识别毕加索。我将Picasso添加到我的依赖项中,我还在课堂上添加了Picasso的导入。

代码部分的屏幕截图 - .with()为红色,因为它没有得到解决

我不会为整个类添加代码,因为它有点大而且会让人感到困惑所以这里是我引用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);

    }

我使用的是Android Studio V3.0.1,Android API 26和Picasso V2.71828。提前致谢。干杯!

android android-studio picasso
1个回答
3
投票

使用这样:

Picasso.get().load(Common.getImage(openWeatherMap.getWeatherList().get(0).getIcon()))
                        .into(imageView);
© www.soinside.com 2019 - 2024. All rights reserved.