我一直在尝试使用 wmqtt.jar 实现 MQTT 服务。像大多数人一样,我从查看其他人的例子开始。我找到了几个对 Dale Lane 帖子http://dalelane.co.uk/blog/?p=1599的引用,并从http://mosquitto.org/2011/11/android-mqtt-example-下载了他的服务版本项目/ . 我的问题是,我尝试在模拟器中使用 wmqtt.jar 运行的每个示例,只要任何使用 java.lang.ClassNotFoundException 引用 MqttSimpleCallback 的类,代码就会崩溃。我必须做一些“特别”的事情来完成这次比赛吗?通常我会假设问题出在我的代码上,但是由于我尝试过的其他来源的所有示例都因同样的问题而崩溃,所以我不得不假设我在设置中遗漏了一些东西?
这是当来自 mosquitto.org 的代码爆炸时我的 LogCat 的样子。
04-13 21:48:59.447: D/AndroidRuntime(303): Shutting down VM
04-13 21:48:59.447: W/dalvikvm(303): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
04-13 21:48:59.548: E/AndroidRuntime(303): FATAL EXCEPTION: main
04-13 21:48:59.548: E/AndroidRuntime(303): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.mosquitto.android.mqttdemo/org.mosquitto.android.mqttdemo.MQTTDemo}: java.lang.ClassNotFoundException: org.mosquitto.android.mqttdemo.MQTTDemo in loader dalvik.system.PathClassLoader[/data/app/org.mosquitto.android.mqttdemo-2.apk]
04-13 21:48:59.548: E/AndroidRuntime(303): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
04-13 21:48:59.548: E/AndroidRuntime(303): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
04-13 21:48:59.548: E/AndroidRuntime(303): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
04-13 21:48:59.548: E/AndroidRuntime(303): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
04-13 21:48:59.548: E/AndroidRuntime(303): at android.os.Handler.dispatchMessage(Handler.java:99)
04-13 21:48:59.548: E/AndroidRuntime(303): at android.os.Looper.loop(Looper.java:123)
04-13 21:48:59.548: E/AndroidRuntime(303): at android.app.ActivityThread.main(ActivityThread.java:4627)
04-13 21:48:59.548: E/AndroidRuntime(303): at java.lang.reflect.Method.invokeNative(Native Method)
04-13 21:48:59.548: E/AndroidRuntime(303): at java.lang.reflect.Method.invoke(Method.java:521)
04-13 21:48:59.548: E/AndroidRuntime(303): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
04-13 21:48:59.548: E/AndroidRuntime(303): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
04-13 21:48:59.548: E/AndroidRuntime(303): at dalvik.system.NativeStart.main(Native Method)
04-13 21:48:59.548: E/AndroidRuntime(303): Caused by: java.lang.ClassNotFoundException: org.mosquitto.android.mqttdemo.MQTTDemo in loader dalvik.system.PathClassLoader[/data/app/org.mosquitto.android.mqttdemo-2.apk]
04-13 21:48:59.548: E/AndroidRuntime(303): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
04-13 21:48:59.548: E/AndroidRuntime(303): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
04-13 21:48:59.548: E/AndroidRuntime(303): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
04-13 21:48:59.548: E/AndroidRuntime(303): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
04-13 21:48:59.548: E/AndroidRuntime(303): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
04-13 21:48:59.548: E/AndroidRuntime(303): ... 11 more