title: android - Paho MQTT service for publishing
body: <p>I am new to Android and services. My aim is to be able to set-up subscriptions and do publications on topic strings. The topic strings and client ID are set-up after parsing input of text fields. I am using the <a href="http://www.eclipse.org/paho/clients/android/">Paho MQTT service</a> (downloaded the source and built the JAR).  </p>
  
  <p>The following causes a Null Pointer Exception at <code>c.publish()</code>. The <code>logcat</code> shows the exception at the <code>IMqttDeliveryToken publish(String topic, MqttMessage message, Object userContext, IMqttActionListener callback)</code> method in <code>MqttAndroidClient</code> where a delivery token is being taken.</p>
  
  <pre><code>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 MemoryPersistence();
                      String clientId = UUID.randomUUID().toString();
                      String brokerUrl = "tcp://m2m.eclipse.org:1883";
                      MqttAndroidClient c = new MqttAndroidClient(getApplicationContext(), brokerUrl, clientId, mPer);
                      try {
                          c.connect(); 
                          String topic = "transfers/topic";
                          String msg = "topic payload"
                          MqttMessage m = new MqttMessage();
                          m.setPayload(msg.getBytes());
                          m.setQos(2);
                          m.setRetained(false);
                          c.publish(topic, m); 
                      } catch (MqttException e) {
                          Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
                      }
  </code></pre>
  
  <p>Can you please tell me how to use the service to publish and subscribe ? I did browse through the sample project (from Paho Android). The LWT and publish seems to be merged as the layout for LWT (<code>activity_publish.xml</code>) seems to be used for publication as well.</p>