开发者

error in setting up an bitmap to an ImageView

I have an app in androi开发者_StackOverflow中文版d where I'm returning some pictures from facebook pages.I return this pictures as InputStream and then I decode them using BitmapFactory something like this:

BitmapFactory.decodeStream(content);

After that I tried to set up this bitmap to an ImageView but I get force close.This is how I do it:

 public Bitmap doInBackground(String...arg0)
        {
            URL profilePicUrl=null;
            int nr=0;
            Bitmap profilePicBitmap=null;
    final String imageURL="http://graph.facebook.com/"+arg0[0]+"/picture?type=small";
                 try{

profilePicBitmap = BitmapFactory.decodeStream((InputStream)new URL(imageURL).getContent());
            System.out.println("Returnam poza numarul:"+profilePicBitmap);

            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
            return profilePicBitmap;
                    }

public void onPostExecute(Bitmap result){
        ImageView imageView_1=null;
        Log.d("We are:","Loaded the pictures");
        imageView_1.setImageBitmap(result);

    }

I use an AsyncTask thread to return the pictures from an URL.But I get error at this line:

imageView_1.setImageBitmap(result);

When I try to display the result returned from decoding the InputStream in here:

profilePicBitmap = BitmapFactory.decodeStream((InputStream)new URL(imageURL).getContent());
                System.out.println("Returnam poza numarul:"+profilePicBitmap);

This is what I get:

android.graphics.Bitmap@44e38ee0
android.graphics.Bitmap@44e22010
android.graphics.Bitmap@44dfbe68
android.graphics.Bitmap@44de26f8
android.graphics.Bitmap@44daa718
android.graphics.Bitmap@44dc30a0
android.graphics.Bitmap@44daa080
android.graphics.Bitmap@44de1680
android.graphics.Bitmap@44df7140
android.graphics.Bitmap@44dae9d8
android.graphics.Bitmap@44e5b008
android.graphics.Bitmap@44e0ee20

This is how my logcat looks like:

java.lang.NullPointerException
at com.SplashScreen.InviteFriends$Task.onPostExecute(InviteFriends.java:214)
at com.SplashScreen.InviteFriends$Task.onPostExecute(InviteFriends.java:1)
at android.os.AsyncTask.finish(AsyncTask.java:417)
at android.os.AsyncTask.access$300(AsyncTask.java:127)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4363)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
at dalvik.system.NativeStart.main(Native Method)

Please help me cause I don't know what is wrong!


In onPostExecute change

ImageView imageView_1=null;

to

ImageView imageView_1= new ImageView(ClassName.this);


there are many question of "How to download image from url" in StackOverflow.

see this download image you could get your solution from this question-answer

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜