I'm trying to use jeromq for an android project. I need to connect to another dealer device. Here is my code :
ZContext zcontext = new ZContext(1);
ZMQ.Socket zsocket = zcontext.createSocket(ZMQ.DEALER);
String identity = "S61_phone";
zsocket.setIdentity(identity.getBytes(ZMQ.CHARSET));
zsocket.connect("tcp://my_other_device_ip_and_port_here");
zsocket.send("test",0);
At the connect call, an error occurs :
2019-09-26 16:59:53.033 18347-18379/? E/AndroidRuntime: FATAL EXCEPTION: Thread-4 Process: com.flir.flironeexampleapplication, PID: 18347 java.lang.NoSuchMethodError: No virtual method clear()Ljava/nio/ByteBuffer; in class Ljava/nio/ByteBuffer; or its super classes (declaration of 'java.nio.ByteBuffer' appears in /system/framework/core-oj.jar) at zmq.Signaler.send(Signaler.java:97) at zmq.Mailbox.send(Mailbox.java:71) at zmq.Ctx.sendCommand(Ctx.java:517) at zmq.ZObject.sendCommand(ZObject.java:382) at zmq.ZObject.sendPlug(ZObject.java:185) at zmq.ZObject.sendPlug(ZObject.java:175) at zmq.Own.launchChild(Own.java:115) at zmq.SocketBase.addEndpoint(SocketBase.java:590) at zmq.SocketBase.connect(SocketBase.java:582) at org.zeromq.ZMQ$Socket.connect(ZMQ.java:2531) at com.flir.flironeexampleapplication.GLPreviewActivity.onDeviceConnected(GLPreviewActivity.java:115) at com.flir.flironesdk.EmbeddedDevice$4.run(EmbeddedDevice.java:512) at java.lang.Thread.run(Thread.java:764)
My environment :
Any idea of what is the problem ? Thanks a lot.
I found an explanation and a workaround here
Java 9 introduces overridden methods with covariant return types for the following methods in java.nio.ByteBuffer that are used by the driver.
- position
- limit
- flip
- clear
In Java 9 they all now return a ByteBuffer , whereas the methods they override return Buffer, resulting in exceptions like this when executing on Java 8 and lower.
This is because the generated byte code includes the static return type of the method, >which is not found on Java 8 and lower because the overloaded methods with covariant >return types don't exist.
The solution is to cast ByteBuffer instances to Buffer before calling the method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With