我正在尝试从图库中选择多个图像并上传它们,这个错误出现在我身上
id
我的活动结果代码就是这个
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.google.android.apps.photos.contentprovider/-1/1/content://media/external/file/14844/ORIGINAL/NONE/827721333 flg=0x1 clip={text/uri-list U:content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Ffile%2F14844/ORIGINAL/NONE/827721333 ...} }} to activity {com.foksart.fixawyBeta/com.foksart.fixawyBeta.ChangeOrder}: android.content.res.Resources$NotFoundException: String resource ID #0x1
at android.app.ActivityThread.deliverResults(ActivityThread.java:3778)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3821)
at android.app.ActivityThread.access$1400(ActivityThread.java:168)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1428)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5665)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:689)
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x1
at android.content.res.HwResources.getText(HwResources.java:1473)
at android.widget.Toast.makeText(Toast.java:298)
at com.foksart.fixawyBeta.ChangeOrder.onActivityResult(ChangeOrder.java:734)
at android.app.Activity.dispatchActivityResult(Activity.java:6602)
at android.app.ActivityThread.deliverResults(ActivityThread.java:3774)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:3821)
at android.app.ActivityThread.access$1400(ActivityThread.java:168)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1428)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:150)
at android.app.ActivityThread.main(ActivityThread.java:5665)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:799)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:689)
我正在使用此上传功能
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1 && resultCode == RESULT_OK && data != null) {
ArrayList<Object> paths=new ArrayList<>();
paths.add(data.getStringArrayListExtra("data"));
Toat.makeText(this,paths.size(),Toast.LENGHT_SHORT).show();
}
}
和文件上传器文件
public void uploadFile(ArrayList<String> imgPaths) {
String charset = "UTF-8";
File sourceFile[] = new File[imgPaths.size()];
for (int i = 0; i < imgPaths.size(); i++) {
sourceFile[i] = new File(imgPaths.get(i));
}
try {
FileUploader multipart = new FileUploader(uploadUrl, charset);
multipart.addHeaderField("User-Agent", "CodeJava");
multipart.addHeaderField("Test-Header", "Header-Value");
multipart.addFormField("description", "Cool Pictures");
multipart.addFormField("keywords", "Java,upload,Spring");
for (int i = 0; i < imgPaths.size(); i++) {
multipart.addFilePart("uploaded_file[]", sourceFile[i]);
}
List<String> response = multipart.finish();
System.out.println("SERVER REPLIED:");
for (String line : response) {
System.out.println(line);
}
} catch (IOException ex) {
System.err.println(ex);
}
}
}
答案 0 :(得分:0)
Toat.makeText(this,paths.size(),Toast.LENGHT_SHORT).show();
这不是你的代码,因为这不会编译(并且,即使它由奇数导入提供,它也不会给出堆栈跟踪中显示的结果)。如果您要在Stack Overflow上提问,请提供实际崩溃的代码,这与堆栈跟踪相匹配。
但是,如果我们将其修复为:
Toast.makeText(this,paths.size(),Toast.LENGTH_SHORT).show();
然后我们得到了与崩溃相匹配的东西:
Caused by: android.content.res.Resources$NotFoundException: String resource ID #0x1
paths.size()
是int
。对邮件采用makeText()
的{{1}}方法需要将其作为字符串资源ID,而不是。{/ p>
通常,对于调试,最好将日志消息发送到LogCat:
int
如果您想坚持Log.e("Something Eye-Catching", String.format("paths.size(): %d", paths.size()));
,请传递Toast
,而不是String
:
int
或:
Toast.makeText(this,String.format("paths.size(): %d", paths.size()),Toast.LENGTH_SHORT).show();