Failure Delivering Result 结果信息
Failure Delivering Result Result Info
我在 Stack Overflow 上对此进行了大量研究,但问题仍然存在。我有一个 main
activity,它为我的 takeapicture
activity 调用 startActivityForResult
。这是我在 takeapicture
中的代码 returns 结果:
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 的第一行出现以下错误:
java.lang.RuntimeException: Failure delivering result ResultInfo{...
...
Caused by: java.lang.NullPointerException
....
看起来 extra 有一个 null
值,但我看不出它哪里出错了。有小费吗?提前致谢。
所有关于 Intent.putExtra(name, value) 的文档都说 'name' 应该包含一个包前缀,而不仅仅是像 "SavedImageDirectory"
这样的字符串
你如何阅读额外的 getStringExtra() ?这可能是问题所在,因为您在该 extra 中设置了一个 File 对象,因此获取 String Extra 的值将为 NULL。
我不确定,但我认为 putExtra("",File)
将是 putExtra()
的 Serializable value
版本,因此您需要将其读作 getSerializableExtra()
或直接添加文件额外的名字
i.putExtra("SavedImageDirectory", pictureFile.getAbsolutePath());
或者更具体地说,您也可以添加文件名
i.putExtra("SavedImageDirectory", pictureFile.getAbsolutePath() + pictureFile.getName());
通过这种方式,您可以将其作为 String Extra 来阅读。
我在 Stack Overflow 上对此进行了大量研究,但问题仍然存在。我有一个 main
activity,它为我的 takeapicture
activity 调用 startActivityForResult
。这是我在 takeapicture
中的代码 returns 结果:
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 的第一行出现以下错误:
java.lang.RuntimeException: Failure delivering result ResultInfo{...
...
Caused by: java.lang.NullPointerException
....
看起来 extra 有一个 null
值,但我看不出它哪里出错了。有小费吗?提前致谢。
所有关于 Intent.putExtra(name, value) 的文档都说 'name' 应该包含一个包前缀,而不仅仅是像 "SavedImageDirectory"
这样的字符串你如何阅读额外的 getStringExtra() ?这可能是问题所在,因为您在该 extra 中设置了一个 File 对象,因此获取 String Extra 的值将为 NULL。
我不确定,但我认为 putExtra("",File)
将是 putExtra()
的 Serializable value
版本,因此您需要将其读作 getSerializableExtra()
或直接添加文件额外的名字
i.putExtra("SavedImageDirectory", pictureFile.getAbsolutePath());
或者更具体地说,您也可以添加文件名
i.putExtra("SavedImageDirectory", pictureFile.getAbsolutePath() + pictureFile.getName());
通过这种方式,您可以将其作为 String Extra 来阅读。