好的,我正在使用 Java 代理循环并将许多 Base64 字符串转换为它们所代表的图像。我在设置 headerVal 时遇到问题。下面是代码块。记录显示我正在获取正文,因为它已经是一个 MIMEEntity,但即使我创建了标题,(两次)这不是他们的任何一次 - 所以我说标题的两行都是空打印。我终于在 header.setHeaderVal("image/png") 行上得到了一个空指针异常。有人可以告诉我我在这里缺少什么吗?
干杯,布赖恩
MIMEEntity body;
if(doc.hasItem("body")){
System.out.println("has MIME body");
body = doc.getMIMEEntity("body");
} else {
System.out.println("before create MIME body");
body = doc.createMIMEEntity();
}
if(body == null){
body = doc.createMIMEEntity();
System.out.println("body was null");
}
System.out.println("after body item");
allObjects.addElement(body);
if (body == null){
System.out.println("hmm, body is null");
}
System.out.println("before header");
//MIMEHeader header = null;
MIMEHeader header = body.createHeader("Content-Type");
System.out.println("after header");
if(header == null ){
System.out.println("header was null???");
header = body.createHeader("Content-Type");
System.out.println("after header null create");
}
allObjects.addElement(header);
if(header == null ){
System.out.println("header was null AGAIN???");
header = body.createHeader("Content-Type");
System.out.println("after header null create AGAIN");
}
System.out.println("after header add object");
header.setHeaderVal("image/png");