这是我在构建应用时遇到的错误
java.lang.NullPointerException:使用null PendingIntent调用cancel() 在android.app.AlarmManager.cancel(AlarmManager.java:901) 在org.eclipse.paho.android.service.AlarmPingSender.stop(AlarmPingSender.java:86) 在org.eclipse.paho.client.mqttv3.internal.ClientComms.shutdownConnection(ClientComms.java:327) 在org.eclipse.paho.client.mqttv3.internal.ClientComms $ ConnectBG.run(ClientComms.java:608) 在java.lang.Thread.run(Thread.java:764)
发出此错误的部分代码是
try {
client = new MqttAndroidClient(getApplicationContext(), "ssl://192.168.43.112:1883", clientId);
InputStream input = getApplicationContext().getResources().openRawResource(R.raw.mynewkeystore);
options = new MqttConnectOptions();
options.setSocketFactory(client.getSSLSocketFactory(input,"password"));
IMqttToken token = client.connect(options);
token.setActionCallback(new IMqttActionListener() {
@Override
public void onSuccess(IMqttToken asyncActionToken) {
//Log.d("Connection", "Connected to Broker ");
//Toast.makeText(getApplicationContext(),"ConnectiontoMQTTBrokerMade", Toast.LENGTH_SHORT).show();
pubConnect.setVisibility(View.INVISIBLE);
pubDisconnect.setVisibility(View.VISIBLE);
pubPub.setVisibility(View.VISIBLE);
ipinputpublish.setVisibility(View.INVISIBLE);
messagemqtt.setVisibility(View.VISIBLE);
}
@Override
public void onFailure(IMqttToken asyncActionToken, Throwable exception) {
// Toast.makeText(getApplicationContext(),"ConnectiontoMQTTBrokerRejected", Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(), exception.getMessage(), Toast.LENGTH_LONG).show();
Log.d("Connection", "Unable to connect to Broker");
}
});
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show();
}
我无法弄清楚为什么会产生这个错误。有人可以帮帮我吗?