无法传递android的结果

无法传递android的结果,android,android-camera,runtime-error,Android,Android Camera,Runtime Error,当用户单击“拍照”按钮时,我的应用程序会将图片保存在外部存储器中。在这种情况下,当我在设备中签入文件夹时,它会工作。但我不明白为什么我的意图等于null,而我在意图中加了额外的值。以及 这是我的密码 private void captureImage(){ //check Is device support a camera?? isDeviceSupportCamera(); if(isDeviceSupportCamera() == true){ //

当用户单击“拍照”按钮时,我的应用程序会将图片保存在外部存储器中。在这种情况下,当我在设备中签入文件夹时,它会工作。但我不明白为什么我的意图等于null,而我在意图中加了额外的值。以及

这是我的密码

private void captureImage(){
    //check Is device support a camera??
    isDeviceSupportCamera();
    if(isDeviceSupportCamera() == true){
        //intent to camera process
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        //สร้างไฟล์ใหม่มาลองรับ รูปที่ถูกถ่าย ไปยัง picDirectory
        imageFile = new File(Environment.getExternalStorageDirectory()+path,
                    "img_"+System.currentTimeMillis()+".jpg");

        startActivityForResult(intent, imageCode);
    }else{
        System.out.println("Your device is not supprot feature camera");
    }

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if(requestCode == imageCode && resultCode == RESULT_OK){



            //add imageFile to array File
            fileCapture.add(imageFile);
            //set adapter
            gridView.setAdapter(new gridviewAdapter(context, fileCapture));


    }else if(requestCode == imageCode && resultCode == RESULT_CANCELED){
        Toast.makeText(getApplicationContext(), "user cancle a image capture", Toast.LENGTH_LONG).show();
    }else{
        Toast.makeText(getApplicationContext(), "Failed to capture", Toast.LENGTH_LONG).show();
    }

}
这是logcat错误

02-07 00:48:05.666: E/AndroidRuntime(18495): FATAL EXCEPTION: main
02-07 09:37:34.625: E/AndroidRuntime(24772): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=100, result=-1, data=Intent { act=inline-data dat=content://media/external/images/media/14298 (has extras) }} to activity {com.example.newlookrecipe/com.example.newlookrecipe.MainActivity}: java.lang.NullPointerException{com.example.newlookrecipe/com.example.newlookrecipe.MainActivity}: java.lang.NullPointerException
02-07 00:48:05.666: E/AndroidRuntime(18495):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3205)
02-07 00:48:05.666: E/AndroidRuntime(18495):    at android.app.ActivityThread.handleSendResult(ActivityThread.java:3248)
02-07 00:48:05.666: E/AndroidRuntime(18495):    at android.app.ActivityThread.access$1200(ActivityThread.java:140)
02-07 00:48:05.666: E/AndroidRuntime(18495):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1285)
02-07 00:48:05.666: E/AndroidRuntime(18495):    at android.os.Handler.dispatchMessage(Handler.java:99)
02-07 00:48:05.666: E/AndroidRuntime(18495):    at android.os.Looper.loop(Looper.java:137)
02-07 00:48:05.666: E/AndroidRuntime(18495):    at android.app.ActivityThread.main(ActivityThread.java:4921)
02-07 00:48:05.666: E/AndroidRuntime(18495):    at java.lang.reflect.Method.invokeNative(Native Method)
02-07 00:48:05.666: E/AndroidRuntime(18495):    at java.lang.reflect.Method.invoke(Method.java:511)
02-07 00:48:05.666: E/AndroidRuntime(18495):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1038)
02-07 00:48:05.666: E/AndroidRuntime(18495):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:805)
02-07 00:48:05.666: E/AndroidRuntime(18495):    at dalvik.system.NativeStart.main(Native Method)
02-07 00:48:05.666: E/AndroidRuntime(18495): Caused by: java.lang.NullPointerException
02-07 00:48:05.666: E/AndroidRuntime(18495):    at com.example.newlookrecipe.MainActivity.onActivityResult(MainActivity.java:96)
02-07 00:48:05.666: E/AndroidRuntime(18495):    at android.app.Activity.dispatchActivityResult(Activity.java:5390)
02-07 00:48:05.666: E/AndroidRuntime(18495):    at android.app.ActivityThread.deliverResults(ActivityThread.java:3201)
02-07 00:48:05.666: E/AndroidRuntime(18495):    ... 11 more
来源:

/**
 * Standard Intent action that can be sent to have the camera application
 * capture an image and return it.
 * <p>
 * The caller may pass an extra EXTRA_OUTPUT to control where this image will be written.
 * If the EXTRA_OUTPUT is not present, then a small sized image is returned as a Bitmap
 * object in the extra field. This is useful for applications that only need a small image.
 * If the EXTRA_OUTPUT is present, then the full-sized image will be written to the Uri
 * value of EXTRA_OUTPUT.
 * @see #EXTRA_OUTPUT
 */
@SdkConstant(SdkConstantType.ACTIVITY_INTENT_ACTION)
public final static String ACTION_IMAGE_CAPTURE = "android.media.action.IMAGE_CAPTURE";
/**
*标准意图动作,可发送至摄像头应用程序
*捕获图像并返回它。
*
*调用者可能会传递一个额外的_输出,以控制将在何处写入此图像。
*如果不存在额外的_输出,则返回一个小尺寸图像作为位图
*额外字段中的对象。这对于只需要小图像的应用程序非常有用。
*如果存在额外的_输出,则完整大小的图像将写入Uri
*额外输出的值。
*@see#额外输出
*/
@SdkConstant(SdkConstantType.ACTIVITY\u INTENT\u ACTION)
公共最终静态字符串ACTION\u IMAGE\u CAPTURE=“android.media.ACTION.IMAGE\u CAPTURE”;
如果没有额外的输出,请注意

因为您包括
intent.putExtra(MediaStore.EXTRA_输出,uri.fromFile(imageFile))
,表示的是一个
意图(MediaStore.ACTION\u IMAGE\u CAPTURE)
,目的是将捕获的映像保存到文件系统。安卓知道你知道图像的位置,所以如果你启动
Intent
而没有指定这个额外的选项,安卓就不会麻烦地返回缩略图像。因为它没有发回数据,所以您的
Intent
对象将为空


如果您想要缩略图,或者要将图像添加到图像视图中,您可以使用您提供给
Intent
Uri

谢谢淹没。如果我想要缩略图图像捕获,我可以从imageFile.getAbsolutePath();。现在我从代码中删除了这一行。“intent.putExtra(MediaStore.EXTRA_OUTPUT,uri.fromFile(imageFile));”,但它仍然是错误的。请您再次检查它。因此,从您提供的代码来看,您甚至没有访问onActivityResult中的intent对象。您确定intent对象为null是问题所在,还是您的“fileCapture”或“gridView”?此外,遵循培训文档可能会有所帮助:谢谢,我尝试了很长时间的代码。现在这不是错误