0

I am trying to set an Image in ImageView from URL using Picasso library. The image is loading from some links like this:

https://pbs.twimg.com/profile_images/638751551457103872/KN-NzuRl.png

But not loading from link like this:

http://imagebin.ca/v/2J37dL9JufmN

I can't figure out what the issue is. I want to load my image from second url, but it's not working.

Here's *MainActivity.java**:

public class MainActivity extends AppCompatActivity {
    ImageView a;
    String Url;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        a = (ImageView) findViewById(R.id.a);

        Url = "MY_URL";

        Picasso.with(getApplicationContext())
                .load(Url)
                .placeholder(R.drawable.bday)
                .into(a);
}
}

Here's a snippet from activity_main.xml

<LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/a" />

</LinearLayout>

I have set required permissions in manifest. I have explored few links similar to this problems but not able to solve this issue. Any help is appreciated.

gautamprajapati
  • 2,055
  • 5
  • 16
  • 31

2 Answers2

0

Try to change like:

Picasso.with(this)
            .load(Url)
            .placeholder(R.drawable.bday)
            .into(a);

Also don't forget to give  

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

to your project's manifest

Abhinav Singh Maurya
  • 3,313
  • 8
  • 33
  • 51
prat
  • 597
  • 8
  • 17
  • I have tried this. Also I have already given Internet access permission in the manifest. BTW thanks, I have myself figured out the problem. The problem is in use of URL. – gautamprajapati Oct 14 '15 at 20:07
0

I myself figured out the problem. I was using a indirect link like this one: http://imagebin.ca/v/2J37dL9JufmN to website hosting the image so it was not being loaded in the ImageView. We should use the direct link to the image to load that particular image which is like this one: https://pbs.twimg.com/profile_images/638751551457103872/KN-NzuRl.png which have file name and its extension in the end.

gautamprajapati
  • 2,055
  • 5
  • 16
  • 31