[英]Android Picasso library not loading image from URL
For some reason Picasso is not loading image from URLs.出于某种原因,Picasso 没有从 URL 加载图像。 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:这是活动的 Java 代码:
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 布局代码:
<?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.我尝试了不同的 URL,但没有成功。
I have already set the permission for Inte.net in Manifest.XML我已经在 Manifest.XML 中设置了 Inte.net 的权限
When I chain the error
with Picasso.with(this).load("https://futurestud.io/images/books/picasso.png").into(mImageView)
(ie当我将
error
与Picasso.with(this).load("https://futurestud.io/images/books/picasso.png").into(mImageView)
(即
Picasso.with(this).load(" https://futurestud.io/images/books/picasso.png ").error(R.drawable.ic_launcher_background). Picasso.with(this).load(" https://futurestud.io/images/books/picasso.png ").error(R.drawable.ic_launcher_background). into(mImageView);
进入(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.
似乎 Picasso 不只从 URL 加载图像。
Please check https://github.com/square/picasso for Picasso library in details.请查看https://github.com/square/picasso了解毕加索图书馆的详细信息。
Maybe you are using the previous version.也许您正在使用以前的版本。 Please add following line in your app level build.gradle file.
请在您的应用程序级 build.gradle 文件中添加以下行。
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'
你应该使用新版本:
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.成功了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.