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

Muh*_*eno 3 android android-studio picasso

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

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

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

我不会为整个类添加代码,因为它很大,可能会引起混淆,因此这是我引用毕加索的函数的整个代码:

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

    }
Run Code Online (Sandbox Code Playgroud)

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

小智 7

像这样使用:

Picasso.get().load(Common.getImage(openWeatherMap.getWeatherList().get(0).getIcon()))
                        .into(imageView);
Run Code Online (Sandbox Code Playgroud)