2012-09-27 4 views
1

이 커버 플로우에 여러 이미지를 표시하는 방법. null 포인터 예외 및 기타 문제가 발생합니다. 얼마나 많은 이미지가 SD 카드에 있는지 모르는 채로 SD 카드에서 이미지를로드하는 방법은 무엇입니까? 이미지 수는 고정되어 있지 않습니다. 이 코드를 사용하여 문제없이 표시하는 하나 개의 이미지를 얻을 수있었습니다 :SD 카드에서 여러 이미지를 가져 와서 Coverflow에 표시

i.setImageBitmap(BitmapFactory.decodeFile("/mnt/sdcard/pic03.png")); 

는 하나 개의 이미지를로드, 즉 하나 개의 동일한 이미지, pic03로 SD 카드에서 지정된 모든 커버 플로우 이미지를 만든 사람 .png, 같은 이미지 하나가 약 12 ​​개가 커버 플로우를 가득 채웠습니다. 그건 좋은데,하지만 나는 SD 카드에있는 모든 이미지를로드하고 싶었습니다. 그래서 각각의 이미지는 커버 플로우의 각 부분을 채우지 만 모든 이미지를 채우는 하나의 동일한 이미지는 채우지 않습니다.

여기를 완전히 잃어 버렸고 Logcat에서 null 포인터 예외가 발생하여 왜 그런지 궁금한가요? 아무도 이것을 작동시키는 법을 알고 있습니까?

여기 아래 코드는 내가 당신에게 아이디어를주기 위해 노력하고있는 코드입니다. SD 카드의 지정된 주소에서 하나의 이미지를로드 할 때 작동한다는 것을 알아 두십시오. 그 부분은 훌륭하게 작동했지만 여러 이미지가 있습니까?

// added this code inside the onCreate method to load the cursor with images only if the IS_PRIVATE column 
// in the sqlite database is equal to the integer 1 

String[] img = { MediaStore.Images.Media._ID }; 
imagecursor = managedQuery(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, img, 
MediaStore.Images.Media.IS_PRIVATE + "='" + 1 +"'",null, MediaStore.Images.Media._ID + ""); 
image_column_index = imagecursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID); 
count = imagecursor.getCount(); 

//------------------------------------------------------------------- 
// ImageAdapter class is a nested class inside of the CoverFlowExample class 

public class ImageAdapter extends BaseAdapter { 
int mGalleryItemBackground; 
private Context mContext; 
private FileInputStream fis; 

// originally earlier version of this app loaded images from the R.drawable folder like this 

private Integer[] mImageIds = { 

    // R.drawable.pic01, 
    // R.drawable.pic02, 
    // R.drawable.pic03, 
    // R.drawable.pic04, 
    // R.drawable.pic05, 
    // R.drawable.pic06, 
    // R.drawable.pic07, 
    // R.drawable.pic08, 
    // R.drawable.pic09 
}; 

//--------------------------------------------------------------------- 
// getView() method that is in the ImageAdapter class that extends the BaseAdapter class 
// this class is a nested class inside the CoverFlowExample class that extends Activity. 
// the CoverFlowExample class is used to implement the coverflow part of the app as an Activity 

public View getView(int position, View convertView, ViewGroup parent) { 
    // to load from resources like SD card 
    ImageView i = new ImageView(mContext); 

// use for single image --> i.setImageBitmap(BitmapFactory.decodeFile("/mnt/sdcard/pic03.png")); 

image_column_index = imagecursor.getColumnIndexOrThrowMediaStore.Images.Media.DATA); 
imagecursor.moveToPosition(position); 

int id = imagecursor.getInt(image_column_index); 
i.setImageURIUri.withAppendedPathMediaStore   .Images.Media.EXTERNAL_CONTENT_URI, ""+ id)); 

// image from R.drawable use --> i.setImageResource(mImageIds[position]); 
i.setLayoutParams(new CoverFlow.LayoutParams(130, 130)); 
i.setScaleType(ImageView.ScaleType.MATRIX);    
return i; 

    // return mImages[position]; <-- not using this as im am not getting image from R.drawable 
} 
+2

STOP 소리, 당신은 DATA 열을 얻으려고하면서이는 imagecursor에 포함 된 유일한 열입니다 String[] img = { MediaStore.Images.Media._ID } 것 같다! IT 부서는 귀하의 질문을 읽으십시오. 그들은 이유 때문에 시프트 키를 발명했습니다. 모든 대문자를 입력하면 텍스트를 읽기가 어려워지고 답을 얻는 속도가 향상되지 않습니다. –

+0

나는 모든 대문자로 된 내 게시물에 5 단어 만 있었지만 모든 대문자 단어를 포함하는 것에 민감하기 때문에 다른 사람들도있을 것이라고 확신합니다. 의도 된 목적은 고함을 지르지 않고 특정 부분을 강조함으로써 텍스트를 더 명확하게 만드는 것입니다. 그러나 어떤 사람들은 동의하지 않습니다. 공평합니다. 여기가 문화라면 5 단어를 소문자로 바꿨습니다. 그러나 나는 SD 카드가 대개 그런 식으로 쓰여졌 기 때문에 "SD"라는 단어를 대문자로 남겼습니다. 어쨌든 코멘트 주셔서 감사합니다. 항상 의사 소통을 향상시키고 커뮤니티와 함께하고 싶습니다. – Kevik

+0

원래 질문의 제목의 90 %가 모두 대문자로되어있어서 내 의견을 올렸을 때 언급 한 내용입니다. 확인할 편집 기록을 확인할 수 있습니다. 강조 할 때까지,이 사이트는 ** bold ** 및 * italic *과'code formatting'을 지원합니다. 그 목적으로 CAPS를 입력 할 필요가 없습니다. 'SD'는 대문자로 적합하며'SDK' 나'IBM'이나'MS-DOS'도 있습니다. –

답변

1

문제는 imagecursor.getColumnIndexOrThrowMediaStore.Images.Media.DATA)

관련 문제