Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. class MyTask extends AsyncTask<String, Void, String> {
  2.  
  3. HttpURLConnection urlConnection = null;
  4. BufferedReader reader = null;
  5. String resultJson = "";
  6.  
  7. @Override
  8. public String doInBackground(String... urls) {
  9. try {
  10.  
  11. URL url = new URL(**LINK**);
  12. urlConnection = (HttpURLConnection) url.openConnection();
  13. urlConnection.setRequestMethod("GET");
  14. urlConnection.connect();
  15.  
  16. InputStream inputStream = urlConnection.getInputStream();
  17. StringBuffer buffer = new StringBuffer();
  18. reader = new BufferedReader(new InputStreamReader(inputStream));
  19.  
  20. String line;
  21. while ((line = reader.readLine()) != null) {
  22. buffer.append(line);
  23. }
  24.  
  25. resultJson = buffer.toString();
  26.  
  27. } catch (Exception e) {
  28. e.printStackTrace();
  29. }
  30. return resultJson;
  31. }
  32.  
  33. @Override
  34. public void onPostExecute(String strJson) {
  35. super.onPostExecute(strJson);
  36. try {
  37. //SONObject dataJsonObj = null;
  38. JSONObject dataJsonObj = new JSONObject(strJson);
  39. Log.d(LOG_TAG, strJson);
  40.  
  41. Log.d(LOG_TAG, "JSON " + dataJsonObj);
  42. } catch (JSONException e) {
  43. e.printStackTrace();
  44. } }
  45.  
  46. org.json.JSONException: End of input at character 0 of
  47.  
  48. java.io.FileNotFoundException: http://api.twitch.tv/kraken/streams/ajfafaasf
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement