I'm trying to display an image in an ImageView with the Picasso Library but I don't know why the image doesn't load. Can you help me please ?
In the build.gradle (dependencies) :
implementation 'com.squareup.picasso:picasso:2.71828'
In the MainActivity.java :
package com.example.imageview;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import com.squareup.picasso.Picasso;
public class MainActivity extends AppCompatActivity {
ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageView = (ImageView) findViewById(R.id.imageView);
Picasso.get().load("http://i.imgur.com/DvpvklR.png").into(imageView);
}
}
In the AndroidManifest.xml : (I don't know if it's really necessary)
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
In the activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="154dp">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:src="#A0A" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
I would like just display the image with the url like in the Picasso's documentation. Did i forget something ? Or change something in settings ?
Thank you !
Your url is not working,
Try this;
Picasso.get().load("https://www.gstatic.com/webp/gallery/4.sm.jpg").into(imageView);
instead of
Picasso.get().load("https://i.sstatic.net/jEIKP.jpg").into(imageView);