2012-05-25 9 views
1

내 sdcard에서 이미지를 읽고 액티비티 내부의 배열에 경로를 저장하고 잘 작동하며이 판독 값은 메소드 내부에 있습니다. 두 번째로, 나는 다른 활동에서 같은 방법을 호출하지만 커서는 null을 반환합니다 ........ 나는 "this"로 문제가 있다고 말할 수는 있지만, 어디에서 변경해야하는지 파악할 수 없습니다. 메소드의 코드 아래.데이터베이스에서 이미지를 처음 읽을 때 Null 포인터 예외가 발생했습니다.

public void LoadImagesFromSDCard() 
{ 
    try 
    { 
     String[] projection = {MediaStore.Images.Media.DATA};   

     ContentResolver cr = this.getContentResolver(); 

     cursor = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,projection,null,null,null); 
     imageCount = cursor.getCount(); 
     imagePath = new String[imageCount + 1]; 
     cursor.moveToFirst(); 

     int cursor_index = 0; 
     do 
     { 
       int id = cursor.getColumnIndex(MediaStore.Images.Media.DATA); 
       imagePath[cursor_index++] = cursor.getString(id); 

     }while(cursor.moveToPosition(cursor_index)); 

    ........ 

난이

Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() { 
    public void onPictureTaken(byte[] imageData, Camera c) { 


     if (imageData != null) { 

      Intent mIntent = new Intent(); 

      StoreByteImage(mContext, imageData, 50,"ImageName"); 
      mCamera.startPreview(); 
      setResult(FOTO_MODE, mIntent); 
      CameraTaken = true; 

      IS.LoadImagesFromSDCard(); 
      finish(); 


     } 
    } 
}; 

같은 다른 활동에서 두번째 호출 실제로 이것은 정보 카메라 활동이다. 도움말 : 여기

에 미리 감사는

E/CameraTest(19169): onCreate 
E/CameraTest(19169): onResume 
E/CameraTest(19169): surfaceCreated 
D/CameraHardwareStub( 34): initHeapLocked: preview size=320x240 
E/CameraTest(19169): surfaceChanged 
D/CameraHardwareStub( 34): initHeapLocked: preview size=320x240 
I/ActivityManager( 59): Displayed activity com.android.print/.CameraActivity: 1013 ms (total 1013 ms) 
D/AudioSink( 34): bufferCount (4) is too small and increased to 12 
I/global (19169): Default buffer size used in BufferedOutputStream constructor. It would be better to be explicit if an 8k buffer is required. 
E/Error reading file(19169): java.lang.NullPointerException 
E/CameraTest(19169): surfaceDestroyed 
E/CameraTest(19169): onStop 
+0

아래 링크를 지칭 아래 코드 란 것은 (IS.LoadImagesFromSDCard에서 IS에게) 갖는다 ..... .... –

+0

로그캣을 첨부 할 수 있습니까? – Tony

+0

IS는 LoadFrom ...() .... – jxgn

답변

0

을 참조하는 로그 캣에게 있습니다. 요점은 나의 첫 번째 활동이 배경에 있고 첫 번째 활동을 배경으로하는 카메라 활동이라고 부릅니다. 그래서 나는 manifest 파일의 첫 번째 활동에 android : launchMode = "singleTask"를 추가해야했습니다. 그럼 내가 명시 적으로 백그라운드에서 실행중인 첫 번째 활동을 호출 IS.LoadImagesFromSDCard();. 그렇게하면 onCreate() 대신 첫 번째 활동에서 onNewIntent()가 호출됩니다. 그리고 onNewIntent() 내에서 LoadFrom ...() 메서드를 호출합니다.

Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() { 
    public void onPictureTaken(byte[] imageData, Camera c) { 


     if (imageData != null) { 

      Intent mIntent = new Intent(); 
      Intent inent = new Intent(); 

      StoreByteImage(mContext, imageData, 50,"ImageName"); 
      mCamera.startPreview(); 
      setResult(FOTO_MODE, mIntent); 
      CameraTaken = true; 
      ImageSelectionIntent.setClassName("your package name", "your package name + class name"); 
      startActivity(intent); 
      finish(); 

하고 처음 활동
protected void onNewIntent(Intent intent) { 
     super.onNewIntent(intent); 
     setIntent(intent);   
     LoadImagesFromSDCard(); 
    } 
     } 
    } 
}; 

communicating between two activities while the one called the other still running in background

관련 문제