-1
這是我的代碼的方法:調用有拋出IOException異常
public class CameraFragment extends Fragment{
String mCurrentPhotoPath = "";
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
try {
dispatchTakePictureIntent(); // Here I try to call this method
} catch (IOException dfg) {
Toast.makeText(getContext(), "ERROR!", Toast.LENGTH_LONG).show();
}
//dispatchTakePictureIntent(); //I can't call this like I did here
return inflater.inflate(R.layout.fragment_camera, container, false);
}
ImageView SkimmedImageImg;
@Override
public void onViewCreated(View view, Bundle savedInstanceState){
super.onViewCreated(view, savedInstanceState);
SkimmedImageImg = (ImageView)view.findViewById(R.id.SkimmedImg);
}
static final int REQUEST_IMAGE_CAPTURE = 1;
private void dispatchTakePictureIntent() throws IOException{
..CODE..
photo = createImageFile();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
..CODE..
}
private File createImageFile() throws IOException{
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DCIM), "Camera");
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
mCurrentPhotoPath = "file:" + image.getAbsolutePath();
return image;
}
}
我怎樣才能解決這個問題? 我不能從每個函數中刪除「throws IOException」,因爲我必須調用「createImageFile()」,並且在沒有「throws IOException」的情況下這不起作用。
有些想法? 謝謝!
你有沒有了解異常處理什麼?特別是'try'或'catch'? –
您之前的回答正確地使用了它......爲什麼你沒有使用該代碼? http://stackoverflow.com/a/42330491/2308683 –
「我該如何解決這個問題?」什麼問題?具體的錯誤是什麼? – Alex