我从我的 sdcard 读取图像并将路径存储在一个活动内的数组中,它工作正常,这个读数在一个方法内。第二次,我从另一个活动中调用相同的方法,但光标返回 null ......我可以说问题出在“this”,但不知道在哪里改变。下面是方法的代码。
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