title: Why am I getting, "incompatible types: Object cannot be converted to String" with this?
body: <p>I'm trying to use the simplest possible code for calling a Web API REST method from an Android app, and the code that I found <a href="http://www.speakingcode.com/2012/09/10/how-to-consume-data-from-a-rest-webservice-or-use-a-web-api-in-android/" rel="noreferrer">here</a> looked very promising:</p>
  
  <pre><code>public String callWebService(String requestUrl)
  {
      String deviceId = "Android Device";
  
      HttpClient httpclient = new DefaultHttpClient();
      HttpGet request = new HttpGet(requestUrl);
      request.addHeader("deviceId", deviceId);
  
      ResponseHandler handler    = new BasicResponseHandler();
      String result = "";
  
      try
      {
          result = httpclient.execute(request, handler); // &lt;= a line too far
      }
      catch (ClientProtocolException e)
      {
          e.printStackTrace();
      }
      catch (IOException e)
      {
          e.printStackTrace();
      }
  
      httpclient.getConnectionManager().shutdown();
  
      return result;
  }
  </code></pre>
  
  <p>However, it won't compile, telling me: "incompatible types: Object cannot be converted to String" on this line:        </p>
  
  <pre><code>result = httpclient.execute(request, handler);
  </code></pre>
  
  <p>It does give a couple of options in an attempt to circumvent the logjam:</p>
  
  <p><img src="https://i.stack.imgur.com/pn9gx.png" alt="enter image description here"></p>
  
  <p>...but I don't know which, if any, of these options is the preferred way to solve this dilemma. Is one way "the way"?</p>
  
  <h2>UPDATE</h2>
  
  <p>This code, as I said, looks promising to me, however I think it's basically unusable as is, because it gives me the dreaded "<em>NetworkOnMainThreadException</em>" From logcat:</p>
  
  <pre><code>04-01 13:18:41.861    1267-1267/hhs.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
  . . .
      java.lang.IllegalStateException: Could not execute method of the activity
  . . .
       Caused by: java.lang.reflect.InvocationTargetException
  . . .
       Caused by: android.os.NetworkOnMainThreadException
  </code></pre>