我是Android和服务的新手.我的目标是能够设置订阅并在主题字符串上做出版物.解析文本字段的输入后,将设置主题字符串和客户端ID.我正在使用Paho MQTT服务(下载源并构建JAR).
以下导致Null指针异常c.publish().在logcat示出了异常的IMqttDeliveryToken publish(String topic, MqttMessage message, Object userContext, IMqttActionListener callback)在方法MqttAndroidClient被截取的输送令牌其中.
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Set locale;
l = getResources().getConfiguration().locale;
}
@Override
protected void onResume() {
super.onResume();
addButtonListener();
}
private void addButtonListener() {
Button submitButton = (Button) findViewById(R.id.buttonSubmit);
submitButton.setOnClickListener(new OnClickListener() {
// ...
// validation code for fields in layout
// ...
// Finally, this.
MemoryPersistence mPer = new …Run Code Online (Sandbox Code Playgroud)