Note that there are some explanatory texts on larger screens.

plurals
  1. POhttpClient.execute(httpPost) causing crash (Android 4.1)
    text
    copied!<p>maybe you can help me out. I'm working on an Android app project that calls on the Rotten Tomatoes API, which returns JSON data. But whenever I run my code the application crashes. The specific bit of code that's giving me problems is httpClient.execute(httpPost);</p> <p>The url string that's being passed to the method is fine and returns the correct data when I type it in my browser, so I know that isn't the problem. I'm kinda at a loss. I've never had an issue with an HttpClient, though in the past I've only worked with XML, never JSON.</p> <p>I've been struggling with this for a while now. If anyone has any insight, it would be greatly appreciated.</p> <pre><code> public JSONObject getJSON(String url) { //Make HTTP Request try { //defaultHttpClient DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); //Log.d("RunTest", url); HttpResponse httpResponse = httpClient.execute(httpPost); // THIS LINE CAUSES APPLICATION TO CRASH HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } catch (UnsupportedEncodingException uee) { Log.d("Exceptions", "UnsupportedEncodingException"); uee.printStackTrace(); } catch (ClientProtocolException cpe) { Log.d("Exceptions", "ClientProtocolException"); cpe.printStackTrace(); } catch (IOException ioe) { Log.d("Exceptions", "IOException"); ioe.printStackTrace(); } 10-27 02:52:44.484: I/Choreographer(627): Skipped 147 frames! The application may be doing too much work on its main thread. 10-27 02:52:44.704: W/dalvikvm(627): threadid=12: thread exiting with uncaught exception (group=0x40a13300) 10-27 02:52:44.724: E/AndroidRuntime(627): FATAL EXCEPTION: AsyncTask #1 10-27 02:52:44.724: E/AndroidRuntime(627): java.lang.RuntimeException: An error occured while executing doInBackground() 10-27 02:52:44.724: E/AndroidRuntime(627): at android.os.AsyncTask$3.done(AsyncTask.java:299) 10-27 02:52:44.724: E/AndroidRuntime(627): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273) 10-27 02:52:44.724: E/AndroidRuntime(627): at java.util.concurrent.FutureTask.setException(FutureTask.java:124) 10-27 02:52:44.724: E/AndroidRuntime(627): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307) 10-27 02:52:44.724: E/AndroidRuntime(627): at java.util.concurrent.FutureTask.run(FutureTask.java:137) 10-27 02:52:44.724: E/AndroidRuntime(627): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230) 10-27 02:52:44.724: E/AndroidRuntime(627): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076) 10-27 02:52:44.724: E/AndroidRuntime(627): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569) 10-27 02:52:44.724: E/AndroidRuntime(627): at java.lang.Thread.run(Thread.java:856) 10-27 02:52:44.724: E/AndroidRuntime(627): Caused by: java.lang.IllegalStateException: Target host must not be null, or set in parameters. scheme=null, host=null, path=api.rottentomatoes.com/api/public/v1.0/lists/movies/box_office.json 10-27 02:52:44.724: E/AndroidRuntime(627): at org.apache.http.impl.client.DefaultRequestDirector.determineRoute(DefaultRequestDirector.java:591) 10-27 02:52:44.724: E/AndroidRuntime(627): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:293) 10-27 02:52:44.724: E/AndroidRuntime(627): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555) 10-27 02:52:44.724: E/AndroidRuntime(627): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487) 10-27 02:52:44.724: E/AndroidRuntime(627): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465) 10-27 02:52:44.724: E/AndroidRuntime(627): at com.example.rottentomatoesclient.JSONParser.getJSON(JSONParser.java:39) 10-27 02:52:44.724: E/AndroidRuntime(627): at com.example.rottentomatoesclient.MoviesActivity$getMovieList.doInBackground(MoviesActivity.java:90) 10-27 02:52:44.724: E/AndroidRuntime(627): at com.example.rottentomatoesclient.MoviesActivity$getMovieList.doInBackground(MoviesActivity.java:1) 10-27 02:52:44.724: E/AndroidRuntime(627): at android.os.AsyncTask$2.call(AsyncTask.java:287) 10-27 02:52:44.724: E/AndroidRuntime(627): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305) 10-27 02:52:44.724: E/AndroidRuntime(627): ... 5 more 10-27 02:52:44.774: W/ActivityManager(148): Force finishing activity com.example.rottentomatoesclient/.MoviesActivity </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload