title: Error in Android client that sends byte[] to a REST web service
body: <p>this is my first post; i'm a newbie on Android development, i wrote a REST web service for receiving a byte[]:</p>
  
  <pre><code>@Path("scp")
  public class ScpResources {
  
      // ...  
  
      @POST
      @Produces("text/plain")
      @Consumes(MediaType.APPLICATION_OCTET_STREAM)    
      public String upload(byte[] input) {
  
          System.out.println("Input: " + new String(input));
  
          return "File Sent!";
      }    
  
  } // End
  </code></pre>
  
  <p>I tested this ws with a java stand alone application(apache httpclient libraries), and everything is ok, but, when i try to do the same thing in the Android application... :</p>
  
  <pre><code>import org.apache.http.client.HttpClient;
  import org.apache.http.client.methods.HttpPost;
  import org.apache.http.entity.ByteArrayEntity;
  import org.apache.http.impl.client.DefaultHttpClient;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.util.Log;
  
  public class MainActivity extends Activity {
  
      private static final String TAG = "MainActivity";   
  
      @Override /** Called when the activity is first created. */    
      public void onCreate(Bundle savedInstanceState) {
  
          super.onCreate(savedInstanceState); 
          setContentView(R.layout.main);
  
          Log.v(TAG, "--------------&gt; to WS");
  
          try {
              HttpClient client = new DefaultHttpClient();
  
              String tmp = "abcdefghijklmnopqrstuvwxyz";
              byte b[] = tmp.getBytes();            
              HttpPost httpPost = new HttpPost("http://192.168.0.116:8080/WSfEclipse/resources/scp");  
  
              ByteArrayEntity entity = new ByteArrayEntity(b);
              entity.setContentType("application/octet-stream");
              httpPost.setEntity(entity);
  
              Log.e(TAG, "&gt;Before error");
              //if(client == null) Log.e(TAG, "HttpClient null");
              //if(httpPost == null) Log.e(TAG, "HttpPost null");            
  
              client.execute(httpPost); // ERROR            
  
          } catch (Exception e) {
              //if(e == null) Log.e(TAG, "Exception(e) null");
              Log.e(TAG, e.getMessage());
          }
  
      } // End : onCreate
  
  } // End : MainActivity
  </code></pre>
  
  <p>... the logcat prints:</p>
  
  <pre><code>ERROR/MainActivity(368):   &gt;Before error
      AndroidRuntime(368):   Shutting down VM
  WARNING/dalvikvm(368):     threadid=1: thread exiting with uncaught exception (group=0x40014760)
  ERROR/AndroidRuntime(368): FATAL EXCEPTION: main
  ERROR/AndroidRuntime(368): java.lang.RuntimeException: Unable to start activity ComponentInfo{.....
  ERROR/AndroidRuntime(368):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1815)
  ERROR/AndroidRuntime(368):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1831)
  ERROR/AndroidRuntime(368):     at android.app.ActivityThread.access$500(ActivityThread.java:122)
  ERROR/AndroidRuntime(368):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1024)
  ERROR/AndroidRuntime(368):     at android.os.Handler.dispatchMessage(Handler.java:99)
  ERROR/AndroidRuntime(368):     at android.os.Looper.loop(Looper.java:132)
  ERROR/AndroidRuntime(368):     at android.app.ActivityThread.main(ActivityThread.java:3948)
  ERROR/AndroidRuntime(368):     at java.lang.reflect.Method.invokeNative(Native Method)
  ERROR/AndroidRuntime(368):     at java.lang.reflect.Method.invoke(Method.java:491)
  ERROR/AndroidRuntime(368):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
  ERROR/AndroidRuntime(368):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
  ERROR/AndroidRuntime(368):     at dalvik.system.NativeStart.main(Native Method)
  ERROR/AndroidRuntime(368): Caused by: java.lang.NullPointerException: println needs a message
  ERROR/AndroidRuntime(368):     at android.util.Log.println_native(Native Method)
  ERROR/AndroidRuntime(368):     at android.util.Log.e(Log.java:230)
  ERROR/AndroidRuntime(368):     at MainActivity.onCreate(MainActivity.java:44)
  ERROR/AndroidRuntime(368):     at android.app.Activity.performCreate(Activity.java:4397)
  ERROR/AndroidRuntime(368):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
  ERROR/AndroidRuntime(368):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1779)
  ERROR/AndroidRuntime(368):     ... 11 more
  </code></pre>
  
  <p>My AndroidManifest.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
            package="com.edu.radiogis.scpecg.clientecelular.activities"
            android:versionCode="1"
            android:versionName="1.0"&gt;
      &lt;uses-sdk android:minSdkVersion="13" /&gt;
  
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
  
      &lt;application android:icon="@drawable/icon" android:label="ClienteSCP"&gt;
          &lt;activity android:name=".MainActivity"
                    android:label="ClienteSCP"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>When i removed the catch code, no errors appear; nevertheless, the application doesn't send the bytes to the web service. I checked if there were null references(Using the code in the comments), but everything was ok. I don't know what is happening, maybe i'm forgetting something.</p>
  
  <p>!!Thanks in advance!! </p>