2015-05-09 87 views
0

我正在嘗試加載存儲在分析中的圖像;使用本教程中的代碼:在我的佈局從分析/ Android中獲取圖像

mProfileImage = mCurrentUser.getParseFile("ProfilePhoto"); 


     mProfilePhoto = (ParseImageView) findViewById(R.id.meal_preview_image); 




     mProfilePhoto.setParseFile(mProfileImage); 
     mProfilePhoto.loadInBackground(new GetDataCallback() { 
      @Override 
      public void done(byte[] data, ParseException e) { 
       mProfilePhoto.setVisibility(View.VISIBLE); 
      } 
     }); 

我有這樣的:https://parse.com/tutorials/mealspotting我寫了這個代碼

<com.parse.ParseImageView 
     android:id="@+id/meal_preview_image" 
     android:layout_width="wrap_content" 
     android:layout_height="200dp" /> 

我用這protected ParseImageView mProfilePhoto;,一個ParseImageView。當我運行應用程序時,圖像不會出現。

+0

檢查,如果這是在AndroidMenifest加入<使用的許可機器人:名稱= 「android.permission.INTERNET對」/> <使用的許可機器人:名稱= 「android.permission.ACCESS_NETWORK_STATE」/> –

回答

2

這就是我通常如何獲得ImageUrl並在ImageView中顯示它,其中也包含圖片緩存機制。你需要parseObject。

String Imgurl; 
ParseFile image = (ParseFile) parseObject.get("ProfilePhoto"); 
if (image!=null) { 
    Log.d("track", image.getUrl()); 
    Imgurl = image.getUrl(); 
} 

然後使用像通用圖像加載器一些圖像緩存庫,以避免OutOfMemory異常和平滑滾動。

imageLoader.displayImage(Imgurl, imageView); 
+0

我我得到一個錯誤:沒有靜態displayImage不能從靜態上下文中引用..我添加了通用圖像加載程序,並遵循此:http://stackoverflow.com/questions/17267671/universal-imageloader-java-io-eofexception。 imageLoader叫什麼? –

+0

你不需要創建類。訪問github和類型的通用圖像加載器。您將被引導如何安裝和設置。 –