android - Squareup Picasso.with() 方法未解决 Android Studio

标签 android android-studio picasso

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

代码部分的屏幕截图 - .with() 为红色,因为它尚未解决

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

我不会为整个类添加代码,因为它有点大并且可能会让人困惑,所以这里是我引用 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。提前致谢。干杯!

最佳答案

像这样使用:

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

关于android - Squareup Picasso.with() 方法未解决 Android Studio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49206039/

相关文章:

java - 如何将 List<Object> 保存到 SharedPreferences?

android - google plus 中的应用邀请

android - 彩信 Intent ACTION_SEND

android - 错误 :Cause: zip file is empty Android studio 0. 8.14

java - Android studio 构建失败,dx.bat 错误

java - 如何在 Picasso 的帮助下获取存储在 Firebase 数据库中的图像

Android - picasso 仅显示占位符,而不显示来自 URL 的图像

Android:带有 GridLayoutManager 的 RecyclerView 中的 Picasso 图像

Android SimpleOnPageChangeListener - 确定滑动方向

安卓设备监视器