我正在使用 Aide,它在 openInputStream 上给了我这个奇怪的错误:
The Exception 'java.io.FileNotFoundException' must be caught or declared in the throws clause
我的代码:
case R.id.album:
intent = new Intent("android.intent.action.GET_CONTENT");
intent.setType("image/*");
startActivityForResult(intent, R.id.album);
break;
case R.id.camera:
intent = new Intent("android.media.action.IMAGE_CAPTURE");
intent.putExtra("output", Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "camera.jpg")));
startActivityForResult(intent, R.id.camera);
break;
protected void onActivityResult(int request, int result, Intent data) {
switch (request) {
case R.id.album:
if (result == -1) {
this.paintView.setPicture(BitmapFactory.decodeStream(getContentResolver().openInputStream(data.getData())));
}
case R.id.camera:
if (result == -1) {
try {
File file = new File(Environment.getExternalStorageDirectory(), "camera.jpg");
this.paintView.setPicture(BitmapFactory.decodeFile(file.toString()));
file.delete();
} catch (Exception e) {
}
}
我没有发现我的代码有任何问题,也许 Aide 需要更多代码,或者它不支持这种代码。我试图从与此类似的其他问题中找出答案,但我一无所获。代码有替代品吗?