Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.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
带有附件的Android电子邮件应用程序不工作_Android_Android Intent_Email Attachments - Fatal编程技术网

带有附件的Android电子邮件应用程序不工作

带有附件的Android电子邮件应用程序不工作,android,android-intent,email-attachments,Android,Android Intent,Email Attachments,我试图开发电子邮件应用程序,我想附加一个图像到它,但我得到NullPointerException。这是我的密码: Uri selectedImage = data.getData(); String[] filePathColumn = {MediaStore.Images.Media.DATA}; Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); curso

我试图开发电子邮件应用程序,我想附加一个图像到它,但我得到NullPointerException。这是我的密码:

Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
columnIndex = cursor.getColumnIndex(filePathColumn[0]);
attachmentfile = cursor.getString(columnIndex);

Log.e("Attachment Path: ", attachmentfile);
URI = Uri.parse("file://" + attachmentfile);
cursor.close();`

请帮帮我

我想你的问题是你没有正确地放置文件路径

以下是我的作品:

Uri.parse("file:///"+attachmentfile));

请注意,文件路径有3/,前两个用于文件头:/,另一个是因为sdcard dir位于文件系统的根目录中,即linux中的/中。

不要求任何给定的SelecteImage Uri是MediaStore知道的,这取决于您从何处获取SelecteImage。改进的缩进,可读性。