0

I want to get an image from a server (HTTPS) and show it in an ImageView.

Images are from Facebook Events (example: https://fbcdn-photos-f-a.akamaihd.net/hphotos-ak-prn1/c17.0.50.50/1016204_538791999501573_1791760778_t.jpg )

 Drawable.createFromStream((InputStream)new URL("https://fbcdn-photos-f-a.akamaihd.net/hphotos-ak-prn1/c17.0.50.50/1016204_538791999501573_1791760778_t.jpg").getContent(), "src");

throws NullPointer Exception

Or maybe is there any way to get the image via Facebook SDK? In Facebook SDK I only know the ProfilePictureView (which may only be for profile pictures???)

Thanks so far!

Hsnbrg
  • 779
  • 3
  • 7
  • 14

4 Answers4

0

have You check internet permission?

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

or user LazyLoading. so you can have cache stored in sdcard and next time you can get image quickly. so use example of this http://www.androidhive.info/2012/07/android-loading-image-from-url-http/

or use another method

public static Bitmap getBitmapFromURL(String src) {
    try {
        Log.e("src",src);
        URL url = new URL(src);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setDoInput(true);
        connection.connect();
        InputStream input = connection.getInputStream();
        Bitmap myBitmap = BitmapFactory.decodeStream(input);
        Log.e("Bitmap","returned");
        return myBitmap;
    } catch (IOException e) {
        e.printStackTrace();
        Log.e("Exception",e.getMessage());
        return null;
    }
}
Sanket Kachhela
  • 10,861
  • 8
  • 50
  • 75
0

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

And I recommend look his: Android - Loading Image Url and Displaying in ImageView

Community
  • 1
  • 1
ƒernando Valle
  • 3,634
  • 6
  • 36
  • 58
0

i recommend you to implement this into your project. It's the best solution. https://github.com/thest1/LazyList

  • NullPointer Exception: 07-16 10:24:20.535: E/AndroidRuntime(1358): at com.fedorvlasov.lazylist.ImageLoader$BitmapDisplayer.run(ImageLoader.java:178) what am I doing wrong? >_ – Hsnbrg Jul 16 '13 at 08:25
  • Line 178 in ImageLoader.java: photoToLoad.imageView.setImageBitmap(bitmap); – Hsnbrg Jul 16 '13 at 08:27
  • what's the constructor you have used? in my case i used this : public ImageLoader imageLoader; imageLoader = new ImageLoader(context.getApplicationContext()); imageLoader.DisplayImage(BeanClass.get(position).imageurl, phonepic); –  Jul 16 '13 at 08:31
  • where's beanClass.get(position).imageurl is the link to the image and phonepic the name of imageview :) –  Jul 16 '13 at 08:32
  • Used the following constructor: ImageLoader imageLoader=new ImageLoader(EventActivity.this); imageLoader.DisplayImage("http://a3.twimg.com/profile_images/548410609/icon_8_73.png", image); – Hsnbrg Jul 16 '13 at 08:40
  • where image is the ImageView ;-) Btw: Why there is ";," displayed after the .png"? If I click edit, it's not shown there :o) – Hsnbrg Jul 16 '13 at 08:42
  • try to add http in android codes. - http:// + + a3.twimg.com/profile_images/548410609/icon_8_73.png –  Jul 16 '13 at 08:46
  • For sure the image is available :P - by the way: the http:// is just cut out by stackoverflow.. – Hsnbrg Jul 16 '13 at 09:09
  • No still get NullPointerException :( – Hsnbrg Jul 16 '13 at 09:11
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/33539/discussion-between-xbjoernx-and-kingomar) – Hsnbrg Jul 16 '13 at 09:11
0

I'm such a dumbass :D

Everything of your answers were right!!!

I displayed the ImageView in a dialog.

I used the following to point to the ImageView

ImageView image = (ImageView)findViewById(R.id.imageView_event_picture);

but for sure this is NULL in a dialog!

It has to be

( final Dialog dialog = new Dialog(EventActivity.this); )

ImageView image = (ImageView)dialog.findViewById(R.id.imageView_event_picture);

I didn't mention that I'm running it out of a dialog - Sorry!!

Hsnbrg
  • 779
  • 3
  • 7
  • 14