4

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 :

  • jeromq 0.5.2
  • target device executing the code is Android 8.1 (Oreo)
  • Compiling in Android Studio with JDK 1.8.0_66 / ndk r10e

Any idea of what is the problem ? Thanks a lot.

Watanka
  • 131
  • 1
  • 10

1 Answers1

6

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.

rafa
  • 326
  • 3
  • 9