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
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!
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
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.
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.
I had to downgrade to Picasso library v.2.5.2 to avoid code debugging which worked faster and easier.
use like this :
Picasso.get().load(Common.getImage(openWeatherMap.getWeatherList().get(0).getIcon()))
.into(imageView);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With