Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 未能传递结果信息_Java_Android - Fatal编程技术网

Java 未能传递结果信息

Java 未能传递结果信息,java,android,Java,Android,我对堆栈溢出进行了大量研究,但问题仍然存在。我有一个主要活动,它为我的TakeApiture活动调用startActivityForResult。以下是我在TakeApiture中返回结果的代码: private Camera.PictureCallback mPicture = new Camera.PictureCallback() { @Override public void onPictureTaken(byte[] data, Camera camera) {

我对堆栈溢出进行了大量研究,但问题仍然存在。我有一个主要活动,它为我的TakeApiture活动调用startActivityForResult。以下是我在TakeApiture中返回结果的代码:

private Camera.PictureCallback mPicture = new Camera.PictureCallback() {

    @Override
    public void onPictureTaken(byte[] data, Camera camera) {
        pictureFile = null;
        try {
            pictureFile = createImageFile(1);
        } catch (Exception e) {System.out.println(e.getCause());
            System.out.println("lol");}
        if (pictureFile == null){
            System.out.println("lol");
            return;
        }

        try {
            System.out.println(Arrays.toString(data));
            FileOutputStream fos = new FileOutputStream(pictureFile);
            fos.write(data);
            fos.close();
        } catch (FileNotFoundException e) {
            System.out.println(e.getCause());
        } catch (IOException e) {
            System.out.println(e.getCause());
        }
        System.out.println(pictureFile.getAbsoluteFile());
        Intent intent = new Intent();
        intent.putExtra("SavedImageDirectory", pictureFile);
        setResult(RESULT_OK, intent);
        finish();
    }
};
运行此命令时,在使用SavedImageDirectory extra的第一行上出现以下错误:


看起来额外的有一个空值,但我看不出哪里会出错。有什么建议吗?提前感谢。

Intent.putExtraname上的所有文档,值表示“name”应该包含一个包前缀,而不仅仅是像SavedImageDirectory这样的字符串。

如何读取额外的getStringExtra?这可能是问题所在,因为您正在该额外值中设置文件对象,因此将值获取为字符串额外值将为NULL

我不确定,但我认为putExtra文件将是putExtra的可序列化值版本,因此您需要将其读取为getSerializableExtra,或者只需在extra中添加文件名

i.putExtra("SavedImageDirectory", pictureFile.getAbsolutePath());
或者更具体地说,您也可以添加文件名

i.putExtra("SavedImageDirectory", pictureFile.getAbsolutePath() + pictureFile.getName());

这样,您就可以将其作为额外的字符串读取。

仍然不起作用。我将其更改为包前缀,但问题仍然存在,并显示相同的错误消息。
i.putExtra("SavedImageDirectory", pictureFile.getAbsolutePath() + pictureFile.getName());