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