最近在搞andriod的java程序,涉及到了web service,需要序列化和反序列化数据
有个方法如下:
public String serializeForObject( Class<?> cls,Object object) throws Exception {
String xmlString="";
JAXBContext jaxbContext=JAXBContext.newInstance(cls);
Marshaller marshaller= jaxbContext.createMarshaller();
StringWriter stringWriter=new StringWriter();
marshaller.marshal(object, stringWriter);
//marshaller.marshal(object, stringWriter);
xmlString= stringWriter.toString();
return xmlString;
}
可是marshaller.marshal(object, stringWriter);这一句下划了红色的波浪线
提示说:
The type javax.xml.stream.XMLEventWriter cannot be resolved. It is indirectly referenced from required .class files
我到网上找了,说要导入stax-api的包。搞了一天多,下了stax-api-1.0jar,stax-api-1.0.1.jar,stax-api-1.0.2.jar,后来又下了javax.xml.stream-1.0.1。jar包。天杀的试每一个都会出现Conversion to Dalvik format failed with error 1错误。
这个问题纠结欲死啊,不导入包出现错误,导入后出现错误。网上搜了一大筐的关于Conversion to Dalvik format failed with error 1错误的解决方案,没一个有用。