Troubleshooting
Why a Flexy Java MQTT client crashes or throws NoSuchMethodError
Short answer
A Flexy Java MQTT application that reboots the device is calling readMessage() on the connection-status event; return immediately when the event number is 1 and read messages only on 0. java.lang.NoSuchMethodError on IOManager.readTagAsFloat is a version boundary, not a missing library: the method needs ETK 1.4.4 and firmware 14.0 together.
On this page
- Why does my Flexy reboot as soon as the Java MQTT application starts?
- What do event 0 and event 1 mean in callMqttEvent?
- Where do I put the guard in MyMQTTClient.java?
- Why does readTagAsFloat throw NoSuchMethodError on IOManager?
- Why does the broker receive my publish but the Java callback never fires?
- Which Java and firmware versions should I build and run this against?
- Does the sample MQTT connection use encryption?
- How do I verify the fix on the device?
- Questions asked
A Flexy that reboots the moment its Java MQTT application starts is not fighting a mysterious version conflict: the sample callback calls readMessage() on the connection-status event, and that call takes the device down. One guarded line that returns on the status event fixes it, and the same application then survives connect, disconnect and receive cycles. The second failure in this stack is quieter: java.lang.NoSuchMethodError on IOManager.readTagAsFloat is not a missing library you can install, it is a firmware boundary that only a matching toolkit-and-firmware pair crosses. Below are the event guard, the meaning of each event number, the exact version pairing, the dispatch checkpoint behind a silent callback, and a verification sequence that proves one layer at a time.
Why does my Flexy reboot as soon as the Java MQTT application starts? #
The sample callback calls readMessage() when callMqttEvent fires with event number 1, a connection-status change, and that call crashes the device; add if (event == 1) return; before the read and the reboot disappears.
The reported reboot case ran on a Flexy 205 with firmware 14.0s0 and ETK 1.4.4 — a matched pair — and it still rebooted, because the crash was never a version problem: every status change walked into the message-reading code. A status change carries no message, so there is nothing for the read to return, and the failing call takes the Java runtime down with the application. The status event also fires when the client first connects at startup, which is why the symptom looks like an instant reboot loop triggered by uploading and starting the code. With the guard in place, the device stays online through broker restarts and WAN drops, because every status transition now exits the callback on its first line.
What do event 0 and event 1 mean in callMqttEvent? #
Event 0 is fired so the application can read an incoming message, and event 1 is fired because the MQTT connection status changed; a status read belongs in that second branch, through getStatus(), never a message read.
Treat the two numbers as two different contracts, not as a sequence. On the message event, readMessage() returns an MqttMessage object or null, and the sample decodes the payload as UTF-8, prints it, and closes the object after use. On the status event, the only sensible work is reading the new connection state with getStatus() — logging a reconnect after a cellular drop, for example — and returning. Data never arrives on the status event, and status never arrives on the message event; code that blurs that line is what produced this crash in the first place.
Where do I put the guard in MyMQTTClient.java? #
Put if (event == 1) return; as the first statement inside the try block of callMqttEvent, ahead of the readMessage() call, so no status transition can ever reach the message-reading path.
The guard is the only change from the published sample; the null check, the UTF-8 decode and the close() call are already there.
public void callMqttEvent(int event) {
try {
if (event == 1) return;
MqttMessage msg;
msg = readMessage();
if (msg != null) {
String str = new String(msg.getPayload(), "UTF-8");
System.out.println("MQTT Message Received: " + str);
msg.close();
}
} catch (Exception e) {
System.out.println("Error callMqttEvent: " + e.toString());
}
}
Keep the whole callback body inside the try block and print the exception string: an exception that escapes a callback can stop the dispatch chain, the same way a Modbus TCP timer stops when its Elapsed handler throws. While debugging, log the numeric event ahead of the guard so a missing dispatch is distinguishable from a null message or a payload-processing failure, and remove that log line once the behavior is proven.
Why does readTagAsFloat throw NoSuchMethodError on IOManager? #
The error means the firmware on the device does not contain the method your compiled code references: IOManager.readTagAsFloat requires ETK 1.4.4 and firmware 14.0 together, so ETK 1.4.4 on firmware 13.2s produces java.lang.NoSuchMethodError.
The device writes it to the real-time event table exactly as:
java.lang.NoSuchMethodError: MQTT_Thread: no method readTagAsFloat with signature (Ljava/lang/String F found in referenced class com.ewon.ewonitf.IOManager or its superclasses
Read that as a linkage failure inside the device: the class is present, the method is not, and the caller is the MQTT thread that received a payload and tried to turn it into a tag value. The reported case ran on a Flexy 102 series device on firmware 13.2s with ETK 1.4.4, and the vendor's answer was that the method is implemented by ETK 1.4.4 together with firmware 14.0, which was only temporarily unavailable at the time. The decision: to call readTagAsFloat, bring the device to that firmware release through its normal update procedure and keep the toolkit at 1.4.4 — updating only the build PC side cannot help, because the missing method lives in the device firmware, not in your project.
Why does the broker receive my publish but the Java callback never fires? #
Three checkpoints fail silently in that situation: the subscription must exist, the main class must call DefaultEventHandler.runEventManager(), and the published topic string must match the subscribed topic exactly, including case.
Receipt at the broker proves the transport; it proves nothing about the Java side. The event manager is what turns socket traffic into callback invocations, so a main class that never calls DefaultEventHandler.runEventManager() leaves callMqttEvent idle forever while the broker log fills up. The subscription call in the sample has the form subscribe(topic, 0) — subscribe at QoS 0 — and topics match literally: in one captured case the publisher sent to abcdef/PLC_TAGS/CONVEYOR_CONTROL while the broker log recorded AXISCADES/PLC_TAGS/CONVEYOR_CONTROL, and a mismatch like that discards every message without an error.
Print both topic strings from the running code and compare them character by character. If the broker's own log shows nothing either, the failure is upstream of the callback; work through Fix a PLC MQTT client that never reaches your broker before touching the Java code again.
Which Java and firmware versions should I build and run this against? #
The sample was built on ETK 1.4.2 with Eclipse; compile with Java 8 or Java 11, run firmware 14.0 before calling readTagAsFloat, and skip the Azure IoT Hub Device SDK, which needs Java SE 8 and will not run on the Flexy.
The later toolkit release is the one that carries readTagAsFloat, so the tag API, not the sample's baseline, sets the minimum on both sides. The toolkit vendor's support portal flags JDK 21 as incompatible with this toolkit generation and points to Java 8 or Java 11 as the build toolchain.
On the SDK question the vendor's answer is blunt: the Azure IoT Hub Device SDK requires Java SE 8, that runtime does not exist on this hardware platform, and a JVM update for it was described as unlikely — the supported route is the device's own MQTT API called from Java or from BASIC. Plan the client around the toolkit MQTT classes from the first commit; there is no waiting out a JVM upgrade on this box.
Does the sample MQTT connection use encryption? #
No — the published example connects to a public broker over unencrypted MQTT, so every tag name and payload in that session is readable on the wire; prove the logic there, but put production tag traffic on a TLS-secured broker connection.
The example's own description says the demo session is plaintext, so treat the sample as a functional test bench and not as a transport design. When you move the client to TLS, expect a new class of startup failure in which the socket opens but no CONNACK ever comes back — the walkthrough of an MQTT TLS connection that gets no CONNACK shows how to isolate the hop that drops the handshake. The guard, the event manager call and the topic checks are transport-independent, so they carry over unchanged.
How do I verify the fix on the device? #
Run these checks in order and stop at the first one that fails, because each proves a separate layer: transport, event dispatch, the guard, message decode, and finally the tag write.
- Upload the corrected application, start it, and let the broker cycle the connection at least twice; the device stays online now that the status event exits the callback immediately.
- Publish a test message to the exact subscribed topic from a second client and confirm the log prints
MQTT Message Received:followed by the UTF-8 payload. - Log the event number ahead of the guard for one pass and confirm a publish arrives as the message event, not the status event; remove the log line afterwards.
- If the payload drives a tag — for example a branch that writes 1.0 to a tag named MACHINE_RUNNING when the payload is ON and 0.0 otherwise — read the tag back after each publish and check it matches the payload branch.
- If
NoSuchMethodErrorstill appears, compare the toolkit and firmware against the pairing in the tag-API section above; updating only the build-side toolkit cannot add a method that lives in the device firmware.
All five passing means the same client pattern is ready to carry real tag traffic — over TLS — without either failure returning.
Questions asked
What does the F at the end of the NoSuchMethodError signature mean?
It is the runtime's type descriptor for the method lookup: one String parameter and a float return. The log text Ljava/lang/String F encodes exactly that signature, so the compiled call and the runtime search agree on the shape. That is what makes the error a pure availability problem: the firmware does not yet contain a method with that shape, and no rebuild of your project can add it.
Can I compile the Java toolkit project with a newer JDK?
Not with the newest ones. The toolkit vendor's support portal notes that JDK 21 may not be compatible with this toolkit generation, so build with Java 8 or Java 11 and keep the compiler level consistent across the IDE and any build scripts. If the device rejects a class at load time, rebuild from source with the older toolchain rather than repackaging the same bytecode.
Does the event guard affect publishing or subscribing?
No. The guard only gates the inbound callback: it stops a status event from entering the message read. Publishing and subscribing are separate calls that never pass through callMqttEvent, so they need no guard and lose nothing by it. If messages stop arriving after you add the guard, suspect the subscription, the topic string or a missing event manager call, because removing the guard brings the crash back without fixing delivery.
What delivery guarantee does the sample subscription make?
The sample subscribes at QoS 0, which the broker honors as at-most-once delivery: no acknowledgments and no retransmission, so a dropped connection can silently drop a message in flight. Keep that in mind whenever a control payload seems to vanish on an unstable link; check which QoS levels your broker and toolkit build accept before raising the number, and test the higher level under a forced disconnect.