MQTT Problem Android App

Hello,

so I’m working on a project for school in which I’m trying to communicate between an app and another device via MQTT. 

This has been my first time using Android Studio and I have used this “guide” to make it work;

However, when I try to run it on the emulator I get the following errors:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.mqtt_done, PID: 7853
java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/localbroadcastmanager/content/LocalBroadcastManager;
at org.eclipse.paho.android.service.MqttAndroidClient.registerReceiver(MqttAndroidClient.java:450)
at org.eclipse.paho.android.service.MqttAndroidClient.connect(MqttAndroidClient.java:428)
at helper.MqttHelper.connect(MqttHelper.java:66)
at helper.MqttHelper.<init>(MqttHelper.java:50)
at com.example.mqtt_done.MainActivity.startMqtt(MainActivity.java:32)
at com.example.mqtt_done.MainActivity.onCreate(MainActivity.java:28)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.ClassNotFoundException: Didn’t find class “androidx.localbroadcastmanager.content.LocalBroadcastManager” on path: DexPathList[[zip file “/data/app/com.example.mqtt_done-4hEBx_aPHTwkbRNACywDbQ==/base.apk”],nativeLibraryDirectories=[/data/app/com.example.mqtt_done-4hEBx_aPHTwkbRNACywDbQ==/lib/x86, /system/lib]]
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 org.eclipse.paho.android.service.MqttAndroidClient.registerReceiver(MqttAndroidClient.java:450) 
at org.eclipse.paho.android.service.MqttAndroidClient.connect(MqttAndroidClient.java:428) 
at helper.MqttHelper.connect(MqttHelper.java:66) 
at helper.MqttHelper.<init>(MqttHelper.java:50) 
at com.example.mqtt_done.MainActivity.startMqtt(MainActivity.java:32) 
at com.example.mqtt_done.MainActivity.onCreate(MainActivity.java:28) 
at android.app.Activity.performCreate(Activity.java:7136) 
at android.app.Activity.performCreate(Activity.java:7127) 
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271) 
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893) 
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048) 
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78) 
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108) 
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808) 
at android.os.Handler.dispatchMessage(Handler.java:106) 
at android.os.Looper.loop(Looper.java:193) 
at android.app.ActivityThread.main(ActivityThread.java:6669) 
at java.lang.reflect.Method.invoke(Native Method) 
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858) 
Process 7853 terminated.

So whenever I run it this happens and the app shuts down.

Like I said, it’s my first time working with Android Studio and I guess it has to do with the LocalBroadcastManager, right?

When I open the path, like for example the “org.eclipse.paho.android.service.MqttAndroidClient.registerReceiver” and look for the LocalBroadcastManager it says “Cannot resolve symbol LocalBroadcastManager”.

Do you maybe have any suggestions on how to fix it?

Thanks in advance :slight_smile:

1 Like

Look at https://stackoverflow.com/questions/51097099/can-not-resolve-import-localbroadcastmanager-on-statement-android-support-v4-con , especially at Dennis van Dalen’s comment:

"For androidx you can use: implementation ‘androidx.localbroadcastmanager:localbroadcastmanager:1.0.0’ – Dennis van Dalen Feb 19 at 8:59"

It worked for me.

1 Like