Try to search your question here, if you can't find : Ask Any Question Now ?

Trying to deserialize object sent over bluetooth

HomeCategory: stackoverflowTrying to deserialize object sent over bluetooth
Avatarcraig asked 3 months ago

Trying to deserialize object sent over bluetooth from one android device to another.

The object size is 126 bytes and I’m taking in exactly that size. However I’m getting a class not found exception.

The code for deserialization is:

public static EcgDataPoint deserialize(byte[] bytes) throws IOException, ClassNotFoundException {
        ByteArrayInputStream b = new ByteArrayInputStream(bytes);
        ObjectInputStream o = new ObjectInputStream(b);
        return (EcgDataPoint) o.readObject();
    }

Error:

tech.abhinavdas.bluetooth D/BluetoothReaderThread: Data type doesn't match
    java.lang.ClassNotFoundException: tech.abhinavdas.bluetoothpairingclient.models.EcgDataPoint
        at java.lang.Class.classForName(Native Method)
        at java.lang.Class.forName(Class.java:453)
        at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:628)
        at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1615)
        at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1520)
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1776)
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1353)
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:373)
        at tech.abhinavdas.bluetooth.models.EcgDataPoint.deserialize(EcgDataPoint.java:54)
        at tech.abhinavdas.bluetooth.threads.BluetoothReaderThread.deserializeAndRead(BluetoothReaderThread.java:47)
        at tech.abhinavdas.bluetooth.threads.BluetoothReaderThread.run(BluetoothReaderThread.java:38)
     Caused by: java.lang.ClassNotFoundException: Didn't find class "tech.abhinavdas.bluetoothpairingclient.models.EcgDataPoint" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/tech.abhinavdas.bluetooth-EZqoTdreOfJT1jU4xbF9dg==/base.apk"],nativeLibraryDirectories=[/data/app/tech.abhinavdas.bluetooth-EZqoTdreOfJT1jU4xbF9dg==/lib/arm64, /system/lib64]]
        at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
        at java.lang.Class.classForName(Native Method) 
        at java.lang.Class.forName(Class.java:453) 
        at java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:628) 
        at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1615) 
        at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1520) 
        at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1776) 
        at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1353) 
        at java.io.ObjectInputStream.readObject(ObjectInputStream.java:373) 
        at tech.abhinavdas.bluetooth.models.EcgDataPoint.deserialize(EcgDataPoint.java:54) 
        at tech.abhinavdas.bluetooth.threads.BluetoothReaderThread.deserializeAndRead(BluetoothReaderThread.java:47) 
        at tech.abhinavdas.bluetooth.threads.BluetoothReaderThread.run(BluetoothReaderThread.java:38) 

What am I missing?

1 Answers
Best Answer
AvatarAmit answered 3 months ago
Your Answer

4 + 5 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com