title: How to create shorten Url using google shortener api
body: <p>i am trying to shorten a url using google shortener api, i tried my luck to find something on google that could help me but i found no blog or something that on java/android that could help me.If someone have a better resources please suggest me. Here's my code </p>
  
  <pre><code>public class tinyurl extends Activity implements OnClickListener {
  EditText original;
  TextView txt;
  
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      Button btn = (Button) findViewById(R.id.Button01);
  
      original = (EditText) findViewById(R.id.edittext);
      txt = (TextView) findViewById(R.id.TextView03);
      btn.setOnClickListener(this);
  }
  
  
  
  @Override
  public void onClick(View v) {
      final String GOOGL_URL = "https://www.googleapis.com/urlshortener/v1/url?key=AIzaSyAau1E_WrYwMiTNqhK5hgH0tyWudyahbOI";
      String tinyUrl = null;
      String original = "http://www.google.com/";
      HttpTransport transport = GoogleTransport.create();
      GoogleHeaders defaultHeaders = new GoogleHeaders();
      transport.defaultHeaders = defaultHeaders;
      transport.defaultHeaders.put("Content-Type", "application/json");
      transport.addParser(new JsonHttpParser());
      HttpRequest request = transport.buildPostRequest();
      request.setUrl(GOOGL_URL);
      GenericData data = new GenericData();
      // data.put("longUrl", "http://www.google.com/");
      data.put("longUrl", original);
      JsonHttpContent content = new JsonHttpContent();
  
      content.data = data;
      request.content = content;
  
      HttpResponse response = null;
      try {
          response = request.execute();
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
          Log.d("eception occured", e.toString());
      }
      Result result = null;
      try {
          result = response.parseAs(Result.class);
          Log.d("TinyUrl", result.shortUrl.toString());
      } catch (IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
  }
  
  public class Result extends GenericJson {
  
      public String shortUrl;
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>all the time i am facing force close due to this line.</p>
  
  <pre><code>response = request.execute();
  </code></pre>
  
  <p>any suggestions?</p>
  
  <p>here is my Stack trace if it gives any help.</p>
  
  <pre><code>   05-12 23:48:55.033: ERROR/AndroidRuntime(455): FATAL EXCEPTION: main
  05-12 23:48:55.033: ERROR/AndroidRuntime(455): java.lang.ExceptionInInitializerError
  05-12 23:48:55.033: ERROR/AndroidRuntime(455):     at com.google.api.client.json.JsonHttpContent.writeTo(JsonHttpContent.java:66)
  05-12 23:48:55.033: ERROR/AndroidRuntime(455):     at com.google.api.client.apache.ContentEntity.writeTo(ContentEntity.java:55)
  05-12 23:48:55.033: ERROR/AndroidRuntime(455):     at org.apache.http.impl.entity.EntitySerializer.serialize(EntitySerializer.java:97)
  05-12 23:48:55.033: ERROR/AndroidRuntime(455):     at org.apache.http.impl.AbstractHttpClientConnection.sendRequestEntity(AbstractHttpClientConnection.java:161)
  05-12 23:48:55.033: ERROR/AndroidRuntime(455):     at org.apache.http.impl.conn.AbstractClientConnAdapter.sendRequestEntity(AbstractClientConnAdapter.java:272)
  05-12 23:48:55.033: ERROR/AndroidRuntime(455):     at org.apache.http.protocol.HttpRequestExecutor.doSendRequest(HttpRequestExecutor.java:237)
  05-12 23:48:55.033: ERROR/AndroidRuntime(455):     at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:119)
  05-12 23:48:55.033: ERROR/AndroidRuntime(455):     at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:410)
  05-12 23:48:55.033: ERROR/AndroidRuntime(455):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
  05-12 23:48:55.033: ERROR/AndroidRuntime(455):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
  05-12 23:48:55.033: ERROR/AndroidRuntime(455):     at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
  05-12 23:48:55.033: ERROR/AndroidRuntime(455):     at com.google.api.client.apache.ApacheHttpRequest.execute(ApacheHttpRequest.java:47)
  05-12 23:48:55.033: ERROR/AndroidRuntime(455):     at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:207)
  05-12 23:48:55.033: ERROR/AndroidRuntime(455):     at com.tinyurl.tinyurl.onClick(tinyurl.java:113)
  05-12 23:48:55.033: ERROR/AndroidRuntime(455):     at android.view.View.performClick(View.java:2408)
  05-12 23:48:55.033: ERROR/AndroidRuntime(455):     at android.view.View$PerformClick.run(View.java:8816)
  05-12 23:48:55.033: ERROR/AndroidRuntime(455):     at android.os.Handler.handleCallback(Handler.java:587)
  05-12 23:48:55.033: ERROR/AndroidRuntime(455):     at android.os.Handler.dispatchMessage(Handler.java:92)
  05-12 23:48:55.033: ERROR/AndroidRuntime(455):     at android.os.Looper.loop(Looper.java:123)
  05-12 23:48:55.033: ERROR/AndroidRuntime(455):     at android.app.ActivityThread.main(ActivityThread.java:4627)
  05-12 23:48:55.033: ERROR/AndroidRuntime(455):     at java.lang.reflect.Method.invokeNative(Native Method)
  05-12 23:48:55.033: ERROR/AndroidRuntime(455):     at java.lang.reflect.Method.invoke(Method.java:521)
  05-12 23:48:55.033: ERROR/AndroidRuntime(455):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
  05-12 23:48:55.033: ERROR/AndroidRuntime(455):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
  05-12 23:48:55.033: ERROR/AndroidRuntime(455):     at dalvik.system.NativeStart.main(Native Method)
  05-12 23:48:55.033: ERROR/AndroidRuntime(455): Caused by: java.lang.NoClassDefFoundError: org.codehaus.jackson.JsonFactory
  05-12 23:48:55.033: ERROR/AndroidRuntime(455):     at com.google.api.client.json.Json.&lt;clinit&gt;(Json.java:56)
  05-12 23:48:55.033: ERROR/AndroidRuntime(455):     ... 25 more
  </code></pre>