'Android Picasso library not loading image from URL
For some reason Picasso is not loading image from URLs. I just see a blank white screen. I have already tried doing solutions to previous questions like these but nothing works for me.
Here is the Java code of Activity:
public class MainActivity extends AppCompatActivity {
ImageView mImageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mImageView = (ImageView) findViewById(R.id.picassoImage);
Picasso.with(this).load("https://futurestud.io/images/books/picasso.png").into(mImageView);
}
}
And here is the XML layout code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.sourabh.usingpicasso.MainActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/picassoImage"/>
</LinearLayout>
Note:-
I tried with different URLs but no luck.
I have already set the permission for Internet in Manifest.XML
When I chain the
errorwithPicasso.with(this).load("https://futurestud.io/images/books/picasso.png").into(mImageView)(iePicasso.with(this).load("https://futurestud.io/images/books/picasso.png") .error(R.drawable.ic_launcher_background). into(mImageView);
) and pass to it an Image from the drawable, the drawable image is displayed. Seems that Picasso is not loading image from URLs only.
Solution 1:[1]
Please check https://github.com/square/picasso for Picasso library in details.
Maybe you are using the previous version. Please add following line in your app level build.gradle file.
implementation 'com.squareup.picasso:picasso:2.71828'
Then in your activity do this.
public class MainActivity extends AppCompatActivity {
ImageView mImageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mImageView = (ImageView) findViewById(R.id.picassoImage);
Picasso.get()
.load("https://futurestud.io/images/books/picasso.png")
.placeholder(R.drawable.placeholder_image)
.error(R.drawable.error_image)
.into(mImageView);
}
}
Solution 2:[2]
Even I was facing this issue on Android Emulator (Device: Pixel 3a XL) and after like few hours trying to fix this, and then I ran the app on the real device the images were being loaded
Solution 3:[3]
You should use new version : implementation 'com.squareup.picasso:picasso:2.71828'
Old Use:
Picasso.with(applicationContext).load(intent.getStringExtra(FLAG))
.into(binding.ivCountryPoster)
New Use:
Picasso.get().load(intent.getStringExtra(FLAG))
.into(binding.ivCountryPoster)
It's worked.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Koushik Mondal |
| Solution 2 | SagaRock101 |
| Solution 3 | Halil Ozel |
