2017-05-20 2 views
0

나는 "putExtra"로 Image를 전달하고 "getExtra"를 사용하여 다른 Activity에서 가져 오기를 클릭하는 List Item을 가진다. 거기에 몇 가지 해결책을 설명하지만 그 중 아무도 나를 위해 일하고 Stackoverflow에 비슷한 질문이 있습니다.getExtra에서 이미지 URL을 받고이를 설정하는 방법

첫 번째 활동 : 나는 두 번째 활동을 검색 할 때

listview.setOnItemClickListener(new AdapterView.OnItemClickListener() { 

      @Override 
      public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) { 
       intent.putExtra("imageurl", elementList.get(position).getImage()); 
       startActivity(intent); 
      } 
     }); 

, 난 아무것도 얻을 수 없다.

E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: https:/tctechcrunch2011.files.wordpress.com/2017/05/battlefield-africa-sponsored.png?w=764&h=400&crop=1 (No such file or directory) 

두 번째 활동 : 내가 그것을

+1

'elementList.get (position) .getImage()'가 반환하는 값은 무엇입니까? –

+0

문자열 URL을 반환합니다. 다음과 같이 : ""https://tctechcrunch2011.files.wordpress.com/2017/05/battlefield-africa-sponsored.png?w=764&h=400&crop=1 " – user45678

답변

1

참고 예외 소스를 극복 할 방법

image = (ImageView) findViewById(R.id.ivImage); 
myUri = Uri.parse(b.getString("imageurl")); 
image.setImageURI(myUri); 

: java.io.FileNotFoundException이 오류 말을 제공합니다. 당신이 Uri 당신이 BitmapFactory#decodeFile에 당신을 이끌 것입니다 지정된 ImageView#setImageURI에 중단 점을 설정하면

: - 파일 경로가 될 것으로 예상된다 Uri와 당신이없는 이상으로부터

public static Bitmap decodeFile(String pathName, Options opts) { 
    Bitmap bm = null; 
    InputStream stream = null; 
    try { 
    stream = new FileInputStream(pathName); 
    bm = decodeStream(stream, null, opts); 
    } catch (Exception e) { 
    /* do nothing. 
     If the exception happened on open, bm will be null. 
    */ 
    Log.e("BitmapFactory", "Unable to decode stream: " + e); 
    } finally { 
    if (stream != null) { 
     try { 
     stream.close(); 
     } catch (IOException e) { 
     // do nothing here 
     } 
    } 
    } 
    return bm; 
} 

을, 문제는 분명하다 따라서 java.io.FileNotFoundException 예외입니다. 비트 맵을 다르게로드해야합니다. Picasso 또는 Glide을 권하고 싶습니다.

관련 문제