하는 검색 여기
//This section turns the database's image URI stored in this cursor into a bitmap, and then sets the ImageView.
Bitmap bitmap = null;
try {
if (............){
Toast.makeText(this, "No image was taken for this item. (TOAST IS JUST TESTING PURPOSES)", Toast.LENGTH_SHORT).show();
}else{
bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), Uri.parse(cursor.getString(cursor.getColumnIndexOrThrow(WineContract.WineEntry.COLUMN_WINE_IMAGE))));
mFullImage.setImageBitmap(bitmap);
}
} catch (IOException e) {
e.printStackTrace();
}
내가 성공하지 시도한 것 중 하나의 예입니다 분리 된 메소드의 렬 치 그런 다음 사용하기 전에 반환 값을 확인하십시오. 이 같은
시도 뭔가 :
가
private String checkDatabaseValue(Cursor cursor){
String result = null;
try{
//This can throw an error if the column is not found
int index = cursor.getColumnIndexOrThrow(WineContract.WineEntry.COLUMN_WINE_IMAGE);
result = cursor.getString(index).trim();
}
catch(Exception ex){
// determine what threw the error and handle appropriately
Log.e(TAG, ex.getMessage());
}
return result;
}
그런 다음 여기 사용
Bitmap bitmap = null;
try {
// I'm assuming you have the cursor from somewhere!!
String imageFile = checkDatabaseValue(cursor);
if (imageFile == null){
Toast.makeText(this, "No image was taken for this item. (TOAST IS JUST TESTING PURPOSES)", Toast.LENGTH_SHORT).show();
return;
}
if(!imageFile.isEmpty()){
bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), Uri.parse(imageFile));
mFullImage.setImageBitmap(bitmap);
else{
Toast.makeText(this, "Empty String. (TOAST IS JUST TESTING PURPOSES)", Toast.LENGTH_SHORT).show();
}
} catch (IOException e) {
e.printStackTrace();
}
으로 업데이트되었습니다. 고마워. 나는 그런 식으로 생각하는 것을 너무 좋아하지 않습니다. 나는 그것을 향상시킬 수 있기를 바랍니다. 그런 방법을 제공해 주셔서 감사합니다. 이제 나는 이런 프로젝트에 대해 어떻게 생각해야하는지에 대한 좋은 본보기를 가지고 있습니다. – andrdoiddev
당신은 여전히 배우면서 (그리고 우리 모두는 아니지만 실제로) 다음과 같은 복합 구문을 사용하지 않도록 노력하십시오 ::'Uri.parse (cursor.getColumnIndexOrThrow (WineContract.WineEntry.COLUMN_WINE_IMAGE))) :: 무엇이 잘못되었는지, 왜 잘못되었는지, 왜 잘못되었는지 알기가 어렵습니다. 당신이 각 가치를 확인할 수 있도록 모든 것을 무너 뜨려 라. – Barns