3
嗨 我正尝试使用Cardme API在Java中创建vcard(.vcf)文件。 我可以保存一个.vcf文件,但它没有内容并且是空的。 请在下面找到我的代码,使用Cardme创建VCard Java
private void generateVCard(Card card){
HelperClass helper = new HelperClass();
VCardImpl vcard = new VCardImpl();
BeginFeature begin = new BeginFeatureImpl();
vcard.setBegin(begin);
vcard.addEmail(helper.formEmailFeature(card));
vcard.addAddress(helper.formAddress(card));
vcard.addPhoto(helper.formPhotoFeature(card));
vcard.addTelephoneNumber(helper.formTelephoneFeature(card));
vcard.setName(helper.formNameFeature(card));
vcard.setFormattedName(helper.formattedName(card));
saveToFile("vc.vcf",vcard);
}
/**
* This function saves a VCard to disk.
*/
public void saveToFile(String fileName , VCard vcard) {
Writer output = null;
File file = new File("fileName");
try {
output = new BufferedWriter(new FileWriter(file));
output.write(vcard.toString());
output.flush();
output.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
欣赏解决此问题的任何帮助。
public电话功能formTelephoneFeature(Card card){ \t \t TelephoneFeaturephoneFeature = new TelephoneFeatureImpl(); \t \t telephoneFeature.setTelephone(card.getContact()。getHmePhn()); \t \t return telephoneFeature; \t} – jshree 2011-04-30 20:47:47
不确定究竟应该做什么?上面的代码块将把VCard输出保存到一个文件中。 – Femi 2011-04-30 20:56:05
对不起,我完全没有完成我最后的评论。我试过你的解决方案。当我在线程“main”中使用formTelephoneFeature()method.Exception时,出现以下错误:info.ineighborhood.cardme.vcard.errors.VCardBuildException:TelephoneFeature(TEL)[info.ineighborhood.cardme.vcard.errors.VCardBuildException ]电话功能(TEL)存在但是为空。 – jshree 2011-04-30 21:02:56