Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Squareup Picasso.with() method unresolved Android Studio

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

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!

like image 379
Muhammad Puspaceno Avatar asked Mar 10 '18 06:03

Muhammad Puspaceno


People also ask

Can Android Studio resolve the with () method of Picasso?

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

How to create a Picasso layout in Android Studio?

Step 1: Create a new project in your android studio and name it as Picasso Example Step 2: Open res -> layout -> xml (or) main. xml and add following code : In this step, we open an XML file and add the code to display a layout in our activity.

What is Picasso in Android?

Picasso allows for hassle-free image loading in your application—often in one line of code! Many common pitfalls of image loading on Android are handled automatically by Picasso: Handling ImageView recycling and download cancelation in an adapter. Complex image transformations with minimal memory use. Automatic memory and disk caching.

Why did I have to downgrade to Picasso library?

I had to downgrade to Picasso library v.2.5.2 to avoid code debugging which worked faster and easier.


1 Answers

use like this :

Picasso.get().load(Common.getImage(openWeatherMap.getWeatherList().get(0).getIcon()))
                        .into(imageView);
like image 120
Milan Hirpara Avatar answered Oct 18 '22 08:10

Milan Hirpara