Madhav Bhattarai
Madhav Bhattarai

Reputation: 867

Unable to load image using Picasso

My code:

  Picasso picasso = Picasso.with(getActivity());
  picasso.load("http://static1.gamespot.com/uploads/original/1550/15507091/2867734-7512874458-CAK00.jpg")
         .error(R.drawable.error)
         .placeholder(R.drawable.placeholder)
         .into(imageView);

Also added required permission in manifest

<uses-permission android:name="ANDROID.PERMISSION.INTERNET" />
<uses-permission android:name="ANDROID.PERMISSION.WRITE_EXTERNAL_STORAGE" />

Edit:

Logcat output

Could not find method java.nio.file.Files.newOutputStream, referenced from method okio.Okio.sink
VFY: unable to resolve static method 19774: Ljava/nio/file/Files;.newOutputStream (Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/io/OutputStream;
VFY: replacing opcode 0x71 at 0x000a
VFY: unable to find class referenced in signature (Ljava/nio/file/Path;)
VFY: unable to find class referenced in signature ([Ljava/nio/file/OpenOption;)
Could not find method java.nio.file.Files.newInputStream, referenced from method okio.Okio.source

Upvotes: 2

Views: 2385

Answers (1)

Luna
Luna

Reputation: 1488

The manifest entries are incorrect. They are case sensitive. Try these:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

If that does not fix it, there could be a connection issue - perhaps a firewall or broken proxy.

You can log errors when Picasso is retrieving images by creating a Picasso.Builder and setting a listener.

Picasso.Builder builder = new Picasso.Builder(getApplicationContext());
builder.listener(new Picasso.Listener() {
    @Override
    public void onImageLoadFailed(Picasso arg0, String arg1) {
        Log.e("Picasso Error", "Failed to load image: " + arg1);
    }
});
Picasso pic = builder.build();
pic.load("http://static1.gamespot.com/uploads/original/1550/15507091/2867734-7512874458-CAK00.jpg")
     .error(R.drawable.error)
     .placeholder(R.drawable.placeholder)
     .into(imageView);

Running with that code, you should see the connection error in logcat.

Upvotes: 4

Related Questions