RabbitMQ Java反序列化ClassNotFound

时间:2014-06-16 09:48:26

标签: serialization bytearray rabbitmq noclassdeffounderror

我正在尝试使用Apache的SerializationUtils将生产者的对象发送给使用者。问题是当我反序列化时出现以下错误:

06-16 11:23:51.443: E/AndroidRuntime(4396): FATAL EXCEPTION: Thread-493
06-16 11:23:51.443: E/AndroidRuntime(4396): org.apache.commons.lang3.SerializationException: java.lang.ClassNotFoundException: Device
06-16 11:23:51.443: E/AndroidRuntime(4396):     at org.apache.commons.lang3.SerializationUtils.deserialize(SerializationUtils.java:230)
06-16 11:23:51.443: E/AndroidRuntime(4396):     at org.apache.commons.lang3.SerializationUtils.deserialize(SerializationUtils.java:268)
06-16 11:23:51.443: E/AndroidRuntime(4396):     at com.homedcs.pushservice.PushLights$1.run(PushLights.java:102)
06-16 11:23:51.443: E/AndroidRuntime(4396):     at java.lang.Thread.run(Thread.java:856)
06-16 11:23:51.443: E/AndroidRuntime(4396): Caused by: java.lang.ClassNotFoundException: Device
06-16 11:23:51.443: E/AndroidRuntime(4396):     at java.lang.Class.classForName(Native Method)
06-16 11:23:51.443: E/AndroidRuntime(4396):     at java.lang.Class.forName(Class.java:217)
06-16 11:23:51.443: E/AndroidRuntime(4396):     at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:2304)
06-16 11:23:51.443: E/AndroidRuntime(4396):     at java.io.ObjectInputStream.readNewClassDesc(ObjectInputStream.java:1663)
06-16 11:23:51.443: E/AndroidRuntime(4396):     at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:683)
06-16 11:23:51.443: E/AndroidRuntime(4396):     at java.io.ObjectInputStream.readNewObject(ObjectInputStream.java:1806)
06-16 11:23:51.443: E/AndroidRuntime(4396):     at java.io.ObjectInputStream.readNonPrimitiveContent(ObjectInputStream.java:787)
06-16 11:23:51.443: E/AndroidRuntime(4396):     at java.io.ObjectInputStream.readObject(ObjectInputStream.java:2006)
06-16 11:23:51.443: E/AndroidRuntime(4396):     at java.io.ObjectInputStream.readObject(ObjectInputStream.java:1963)
06-16 11:23:51.443: E/AndroidRuntime(4396):     at org.apache.commons.lang3.SerializationUtils.deserialize(SerializationUtils.java:224)
06-16 11:23:51.443: E/AndroidRuntime(4396):     ... 3 more
06-16 11:23:51.443: E/AndroidRuntime(4396): Caused by: java.lang.NoClassDefFoundError: Device
06-16 11:23:51.443: E/AndroidRuntime(4396):     ... 13 more
06-16 11:23:51.443: E/AndroidRuntime(4396): Caused by: java.lang.ClassNotFoundException: Device
06-16 11:23:51.443: E/AndroidRuntime(4396):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
06-16 11:23:51.443: E/AndroidRuntime(4396):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
06-16 11:23:51.443: E/AndroidRuntime(4396):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
06-16 11:23:51.443: E/AndroidRuntime(4396):     ... 13 more
06-16 11:26:14.140: E/Trace(4444): error opening trace file: No such file or directory (2)

这是设备类

package com.homedcs.models;

import java.io.Serializable;

public class Device implements Serializable {

private static final long serialVersionUID = 1L;

private int id, type, slaveAddress, channel, value, power, config, location;

public Device() {

}

public Device(int id, int type, int slaveAddres, int channel, int value, int power, int config, int location) {

    this.id = id;
    this.type = type;

}

public int getId() {
    return id;
}

public void setId(int id) {
    this.id = id;
}

public int getType() {
    return type;
}

public void setType(int type) {
    this.type = type;
}

}

我在互联网上搜索了一些关于classpath的内容。我仍然不知道如何解决这个问题。

1 个答案:

答案 0 :(得分:0)

我使用apache thrift来制作跨平台对象。 你只需制作一个节俭文件,用你想要的语言生成课程,非常有帮助,非常容易!