我使用了 Paho Eclipse repo 中的 Android Service jar。在客户端连接后订阅任何主题时,我遇到了 NUllPOinterException。
public void connect(View view) {
MqttConnectOptions conOpt = new MqttConnectOptions();
String uri = "tcp://" + host + ":" + port;
boolean cleanSession = true;
// int timeout = 60 ;
// int keepalive = 60 ;
clientHandle = uri + clientId;
MqttAndroidClient client;
client = Connections.getInstance(this)
.createClient(this, uri, clientId);
Connection conn = new Connection(clientHandle, clientId, host, port,
this, client, sslConnection);
conOpt.setCleanSession(cleanSession);
// conOpt.setConnectionTimeout(timeout);
conOpt.setKeepAliveInterval(100);;
MqttCallbackHandler callback = new MqttCallbackHandler(this,
MainActivity.this, clientHandle); …Run Code Online (Sandbox Code Playgroud)