2011-07-19 5 views
0

をビットマップを設定するには、私はFacebookのpages.Iからいくつかの写真を返すよアンドロイドでアプリがInputStreamとしてこの絵を返す必要があり、その後、私は彼らがこのようなBitmapFactory何か使用してデコード:エラーがImageViewの

BitmapFactory.decodeStream(content); 

その後、私はImageViewにこのビットマップを設定しようとしたが、私は力close.Thisを取得し、私はそれを行う方法です。

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); 

    } 

私はURL.But Iから画像を返すためにAsyncTaskスレッドを使用次の行にエラーが表示されます。

imageView_1.setImageBitmap(result); 

私は結果を表示してみてくださいここでInputStreamをデコードから返さ:

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

これは私が得るものです:

[email protected] 
[email protected]10 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 

これは私のlogcatがどのように見えるかです:

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) 

私は何が間違っているのかわからないのを助けてください!

+2

ImageViewのimageView_1 = NULL; Log.d( "We are:"、 "画像をロードしました"); imageView_1.setImageBitmap(result); それはどういう意味ですか? imageViewをnullに設定してから、それを呼び出そうとしていますか?あなたがNullPointerを手に入れても不思議ではない – Egor

答えて

2

ImageView imageView_1= new ImageView(ClassName.this); 
1

からonPostExecute変更

ImageView imageView_1=null; 

では、 "どのようにURLから画像をダウンロードするには、" StackOverflowの中をの多くの質問があります。

は、あなたがこの質問の答えからあなたのソリューションを得ることができる。このdownload image参照

+0

Ok ...私はそれを自分で得た...ちょうど時々私はとても鈍いです! – adrian

+0

@adrian hey hola!私はイメージビューアを使用していますが、私はイメージを変えずに、イメージを変更することができます。[link de mi pregunta](http:// stackoverflow。 com/questions/26886415)。 a ver s es alguna chorrada queいいえconsigo ver、 –