Squareup Picasso.with()方法未解决的Android Studio [英] Squareup Picasso.with() method unresolved Android Studio

查看:630
本文介绍了Squareup Picasso.with()方法未解决的Android Studio的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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

    }

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

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

推荐答案

使用如下:

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

这篇关于Squareup Picasso.with()方法未解决的Android Studio的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆