我是MQTT
新手paho Libs for Android
。今天我尝试创建一个简单的连接示例,如下所示,但是发生的情况是,logcat
尽管代码中没有错误,但在运行时,我从下面发布的错误消息中得到了 eclipse 说can not run the projects due to errors "which are not exist"
或应用程序崩溃,我得到了下面发布的错误日志。
此外,我在我的项目中的库图片下方发布了一张图片,这些库是从paho website
.
请让我知道我错过了什么以及我做错了什么。
代码:
public class MQTT_00 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mqtt_00_layout);
MqttClientPersistence persistence = null;
try {
persistence = new MqttDefaultFilePersistence("/temp/");
} catch (MqttPersistenceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
MqttClient client = new MqttClient("tcp://localhost:1883", "MQTTSub", persistence);
MqttConnectOptions opts = new MqttConnectOptions();
opts.setKeepAliveInterval(480);
opts.setWill(client.getTopic("willTopic"), "something bad happened".getBytes(), 1, true);
client.connect(opts);
} catch (MqttException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
日志猫:
11-10 12:52:49.617: E/AndroidRuntime(30700): FATAL EXCEPTION: main
11-10 12:52:49.617: E/AndroidRuntime(30700): Process: com.example.mqtt_00, PID: 30700
11-10 12:52:49.617: E/AndroidRuntime(30700): java.lang.NoClassDefFoundError:
org.eclipse.paho.client.mqttv3.MqttDefaultFilePersistence
11-1 12:52:49.617: E/AndroidRuntime(30700): at
com.example.mqtt_00.MQTT_00.onCreate(MQTT_00.java:21)
11-10 12:52:49.617: E/AndroidRuntime(30700): at
android.app.Activity.performCreate(Activity.java:5389)
11-10 12:52:49.617: E/AndroidRuntime(30700): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
11-10 12:52:49.617: E/AndroidRuntime(30700): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2246)
11-10 12:52:49.617: E/AndroidRuntime(30700): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2340)
11-10 12:52:49.617: E/AndroidRuntime(30700): at
android.app.ActivityThread.access$800(ActivityThread.java:157)
11-10 12:52:49.617: E/AndroidRuntime(30700): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247)
11-10 12:52:49.617: E/AndroidRuntime(30700): at
android.os.Handler.dispatchMessage(Handler.java:102)
11-10 12:52:49.617: E/AndroidRuntime(30700): at android.os.Looper.loop(Looper.java:157)
11-10 12:52:49.617: E/AndroidRuntime(30700): at
android.app.ActivityThread.main(ActivityThread.java:5293)
11-10 12:52:49.617: E/AndroidRuntime(30700): at java.lang.reflect.Method.invokeNative(Native
Method)
11-10 12:52:49.617: E/AndroidRuntime(30700): at
java.lang.reflect.Method.invoke(Method.java:515)
11-10 12:52:49.617: E/AndroidRuntime(30700): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
11-10 12:52:49.617: E/AndroidRuntime(30700): at c
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
11-10 12:52:49.617: E/AndroidRuntime(30700): at dalvik.system.NativeStart.main(Native Method)
图片