开发者

Android: com.sun.org.apache.xerces.internal.dom: ClassNotFoundException

开发者 https://www.devze.com 2023-01-17 06:50 出处:网络
I am developing an Android application at the moment, and I\'m facing a problem that i have no idea how to solve.

I am developing an Android application at the moment, and I'm facing a problem that i have no idea how to solve.

My application communicates with a Tomcat Server, and i'm using ObjectOutputStream to send a Document object to my application from my servlet.

Therefore, I'm importing org.w3c.dom in my project. The problem I'm facing is that I can't read the Document object with ObjectInputStream on my android device.

I'm getting the following exception.

com.sun.org.apache.xerces.internal.dom: ClassNotFoundException 

on the lines:

ObjectInputStream ois = new ObjectInputStream(conn.getInputStream());
Document doc = (Document) ois.readObject();     
ois.close();

I can send and 开发者_如何学编程receive any object I want without any problem, but when I try to send an object referred to the com.w3c.dom package I get this exception.

Can anybody help?


The Sun JVM implementation of org.w3c.Document uses a class situated in a package that is included only in the Sun JVM (as the "com.sun.something" package name hints.)

When the Android Dalvik VM tries to deserialize the Object in readObject, it finds a reference to that internal, Sun JVM specific, class - because the Dalvik VM does not have a reference to that class (Dalvik's org.w3c.Document implementation is different), an exception is thrown. (More generally, Java Object serialization/deserialization is supposed to work only if both serializer and deserializer share the same class implementation. I suspect that most of your deserialization routines would fail if your instance of Tomcat was not running on a Sun JVM.)

Seeing that you are sending org.w3c.Document objects, and that this class natively represents an XML document, you could solve the problem by sending an XML stream rather than an Object stream.

0

精彩评论

暂无评论...
验证码 换一张
取 消