title: org.eclipse.paho.android.service how the sample code run?
body: <p>I am a newbie with android. I want to use org.eclipse.paho.android.service(<a href="http://www.eclipse.org/paho/files/android-javadoc/index.html" rel="nofollow" title="here">here</a>) to connect to the Mqtt Server. I have read the document and I have implement <code>IMqttActionListener</code>, <code>MqttCallback</code> and <code>MqttTraceHandler</code>. Then I use the MqttAndroidClient to connect to the server, but I can't connect the server. I have debug the android code, but It seems helpless.</p>
  
  <p>My sample code is below.</p>
  
  <pre><code>ActionListener acListener = new ActionListener(this.context,ActionListener.Action.CONNECT,this.clientHandle,null);
  MqttConnectOptions connOpt = new MqttConnectOptions();
  
  //connOpt.setConnectionTimeout(10);
  connOpt.setKeepAliveInterval(1000);
  
  this.client.setCallback(new MqttCallbackHandler(this.context,this.clientHandle));
  this.client.setTraceCallback(new MqttTraceCallback());
  
  try{
      this.client.connect(connOpt,null, acListener);
  } catch (MqttException e){
      Log.e(this.getClass().getCanonicalName(),"----------------------------------------",e);
  }
  
  if(this.client.isConnected()) {
      Log.i("connect", "------------------------------------");
  } else {
     *Log.i("is not connect", "----------------------------------");
  }
  </code></pre>
  
  <p>Always the program will tell me that the client is not connect to the server.I have no idea with that.</p>
  
  <p>There is a exception:</p>
  
  <pre><code>com.example.zhangkai.gpstraker E/AndroidRuntime: FATAL EXCEPTION: main
  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.zhangkai.gpstraker/com.example.zhangkai.gpstraker.GPSActivity}: java.lang.NullPointerException
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2312)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2364)
  at android.app.ActivityThread.access$600(ActivityThread.java:162)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1346)
  at android.os.Handler.dispatchMessage(Handler.java:99)
  at android.os.Looper.loop(Looper.java:153)
  at android.app.ActivityThread.main(ActivityThread.java:5320)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:511)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:851)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
  at dalvik.system.NativeStart.main(Native Method)
  Caused by: java.lang.NullPointerException
  at org.eclipse.paho.android.service.MqttAndroidClient.publish(MqttAndroidClient.java:812)
  at org.eclipse.paho.android.service.MqttAndroidClient.publish(MqttAndroidClient.java:668)
  at com.example.zhangkai.gpstraker.MqttConnection.connect(MqttConnection.java:128)
  at com.example.zhangkai.gpstraker.GPSActivity.onCreate(GPSActivity.java:27)
  at android.app.Activity.performCreate(Activity.java:5265)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2276)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2364)?
  at android.app.ActivityThread.access$600(ActivityThread.java:162)?
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1346)?
  at android.os.Handler.dispatchMessage(Handler.java:99)?
  at android.os.Looper.loop(Looper.java:153)?
  at android.app.ActivityThread.main(ActivityThread.java:5320)?
  at java.lang.reflect.Method.invokeNative(Native Method)?
  at java.lang.reflect.Method.invoke(Method.java:511)?
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:851)?
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)?
  at dalvik.system.NativeStart.main(Native Method)?
  </code></pre>
  
  <p>After debug the app . the EXCEPTION is because the mqttService is null.But Now I get another exception</p>
  
  <pre><code>    E/AndroidRuntime: FATAL EXCEPTION: main
   java.lang.RuntimeException: Error receiving broadcast Intent { act=android.net.conn.CONNECTIVITY_CHANGE flg=0x8000010 (has extras) } in org.eclipse.paho.android.service.MqttService$NetworkConnectionIntentReceiver@415460e8
  at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:820)
  at android.os.Handler.handleCallback(Handler.java:725)
  at android.os.Handler.dispatchMessage(Handler.java:92)
  at android.os.Looper.loop(Looper.java:153)
  at android.app.ActivityThread.main(ActivityThread.java:5320)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:511)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:851)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
  at dalvik.system.NativeStart.main(Native Method)
  sed by: java.lang.SecurityException: ConnectivityService: Neither user 10090 nor current process has android.permission.ACCESS_NETWORK_STATE.
  at android.os.Parcel.readException(Parcel.java:1425)
  at android.os.Parcel.readException(Parcel.java:1379)
  at android.net.IConnectivityManager$Stub$Proxy.getActiveNetworkInfo(IConnectivityManager.java:720)
  at android.net.ConnectivityManager.getActiveNetworkInfo(ConnectivityManager.java:570)
  at org.eclipse.paho.android.service.MqttService.isOnline(MqttService.java:814)
  at org.eclipse.paho.android.service.MqttService$NetworkConnectionIntentReceiver.onReceive(MqttService.java:796)
  at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:808)
  at android.os.Handler.handleCallback(Handler.java:725)?
  at android.os.Handler.dispatchMessage(Handler.java:92)?
  at android.os.Looper.loop(Looper.java:153)?
  at android.app.ActivityThread.main(ActivityThread.java:5320)?
  at java.lang.reflect.Method.invokeNative(Native Method)?
  at java.lang.reflect.Method.invoke(Method.java:511)?
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:851)?
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)?
  at dalvik.system.NativeStart.main(Native Method)?
  </code></pre>
  
  <p>My AndroidManifest.xml is </p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  &lt;uses_permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt;
  &lt;uses_permission android:name="android.permission.CHANGE_NETWORK_STATE"/&gt;
  &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /&gt;
  </code></pre>