简体   繁体   中英

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:-

  1. I tried with different URLs but no luck.

  2. I have already set the permission for Inte.net in Manifest.XML

  3. When I chain the error with Picasso.with(this).load("https://futurestud.io/images/books/picasso.png").into(mImageView) (ie

    Picasso.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.

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

即使我在 Android Emulator(设备:Pixel 3a XL)上也遇到了这个问题,在尝试解决这个问题几个小时后,然后我在真实设备上运行了应用程序,图像正在加载

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM