gpt4 book ai didi

java - 无法读取带有地址的电子名片

转载 作者:行者123 更新时间:2023-12-01 15:12:23 24 4
gpt4 key购买 nike

请看下面的代码

package vcardtest;

import java.io.*;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sourceforge.cardme.engine.VCardEngine;
import net.sourceforge.cardme.vcard.VCard;
import net.sourceforge.cardme.vcard.features.*;
import net.sourceforge.cardme.vcard.types.parameters.TelephoneParameterType;
import net.sourceforge.cardme.vcard.types.parameters.XTelephoneParameterType;

public class VCardTest
{

public static void main(String[] args)
{
File vcardFile = new File("C:/Users/yohan/Contacts/Akon Kon.vcf");
VCardEngine vcardEngine = new VCardEngine();
try
{
VCard vcard = vcardEngine.parse(vcardFile);
String name = vcard.getName().getGivenName();

if(vcard.hasEmails())
{
EmailFeature email = vcard.getEmails().next();
String sEmail = email.getEmail();
System.out.println(sEmail);
}


if(vcard.hasNicknames())
{
NicknameFeature nickName = vcard.getNicknames();
Iterator<String> nicknames = nickName.getNicknames();
String sNickName = nicknames.next();
System.out.println(sNickName);
}


// if(vcard.hasAddresses())
//{
//Iterator<AddressFeature> addresses = vcard.getAddresses();
//AddressFeature address = addresses.next();
//String streetAddress = address.getStreetAddress();
//System.out.println(streetAddress);
//}
String telephone = "";


//Getting the phone numbers

Iterator<TelephoneFeature> itNumbers = vcard.getTelephoneNumbers();

while (itNumbers.hasNext())
{

TelephoneFeature next1 = itNumbers.next();
telephone = next1.getTelephone();

// System.out.println(telephone);
System.out.println("types = " + next1.getExtendedTelephoneParameterSize());

Iterator<XTelephoneParameterType> itTypes = next1.getExtendedTelephoneParameterTypes();

Iterator<TelephoneParameterType> itNTypes = next1.getTelephoneParameterTypes();

while (itNTypes .hasNext())
{

TelephoneParameterType next = itNTypes .next();
System.out.println(" - " + next.getType() + " / " + next.getDescription());

if(next.getType().equals("CELL"))
{
System.out.println("Cell Phone Number: " + next1.getTelephone());
}
else if(next.getType().equals("HOME"))
{
System.out.println("Home Number is: " + next1.getTelephone());
}

}

}



System.out.println("---------------------------------------------------------------------");
System.out.println( name );


//System.out.println(streetAddress);



} catch (IOException ex)
{
ex.printStackTrace();
}
}
}

如果我传递带有地址的 VCard,则会生成以下错误

run: Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/codec/net/QuotedPrintableCodec at net.sourceforge.cardme.engine.VCardEngine.parseLabelType(VCardEngine.java:1432) at net.sourceforge.cardme.engine.VCardEngine.parseLine(VCardEngine.java:523) at net.sourceforge.cardme.engine.VCardEngine.parseVCard(VCardEngine.java:348) at net.sourceforge.cardme.engine.VCardEngine.parse(VCardEngine.java:254) at vcardtest.VCardTest.main(VCardTest.java:22) Caused by: java.lang.ClassNotFoundException: org.apache.commons.codec.net.QuotedPrintableCodec at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:423) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:356) ... 5 more Java Result: 1 BUILD SUCCESSFUL (total time: 2 seconds)

按照我使用的测试VCard,它是由我的手机生成的,发送到笔记本电脑并转换为.contact,并使用Windows联系人文件夹中的选项手动转换回.vcf。

BEGIN:VCARD
VERSION:2.1
N:Kon;Akon
FN:Akon Kon
TEL;CELL;VOICE:0711111111
ADR;HOME:;;195;Colj;Sri lanka
LABEL;HOME;ENCODING=QUOTED-PRINTABLE:195=0D=0AColj, Sri lanka
EMAIL;PREF;INTERNET:akok@a.com
REV:20120828T061900Z
END:VCARD

请帮忙!

最佳答案

您似乎缺少 Apache Commons Codec library

您需要下载它及其依赖项并将它们添加到您的类路径

关于java - 无法读取带有地址的电子名片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12153852/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com