title: Troubleshooting JSONException: End of input at character 0
body: <p>I am doing a search on Active.com using their API and currently my search is getting stuck at this error : org.json.JSONException: End of input at character 0. I am a newbie,Any help is appreciated.</p>
  
  <p><strong>MainActivity</strong></p>
  
  <pre><code>      private class SearchTask extends AsyncTask&lt;String, Integer, String&gt;
  {
      ProgressDialog dialog;
  
          @Override
          protected void onPreExecute() {
  
              dialog = ProgressDialog.show(StayActiveActivity.this,"","Please Wait...");
  
              super.onPreExecute();
          }
  
          @Override
          protected String doInBackground(String... params) {
              try {
                  String result = ActiveHelper.download(params [0]);
                  return result;
              } catch (ApiException e) {
                  e.printStackTrace();
                  Log.e("alatta", "Problem making search request");
              }
              return "";
          }
          @Override
          protected void onPostExecute(String result) {
  
              try {
                  JSONObject obj = new JSONObject(result);
                  m_results = obj.getJSONArray("results");
                  if (m_results == null || m_results.length() == 0)
                  {
                      Toast.makeText(getApplicationContext(),
                              "No Results found for " + m_search_text.getText(), 
                              Toast.LENGTH_LONG).show();
  
                  }
                  else
                      m_search_results.setAdapter(new JSONAdapter(getApplicationContext()));
              } catch (JSONException e) {
                  e.printStackTrace();
              }
          }
      }
  
  private class JSONAdapter extends BaseAdapter
  {
      public JSONAdapter(Context c){
  
      }
  
      public int getCount() 
      {
      return  m_results.length();
          }
  
      public Object getItem(int arg0){
          return null;
      }
  
      public long getItemId(int pos){
          return pos;
  
      }
  
      public View getView(int pos, View convertView, ViewGroup parent) {
          View tv;
          TextView t;
  
          if (convertView == null)
              tv = m_inflater.inflate (R.layout.item, parent, false);
          else
              tv = convertView;
          try {
              /* For each entry in the ListView, we need to populate 
               * its text and timestamp */
              t = (TextView) tv.findViewById(R.id.text);
              JSONObject obj = m_results.getJSONObject(pos);
  
              t.setText (obj.getString("event") + ": " + 
                          obj.getString("text"));
  
              t = (TextView) tv.findViewById(R.id.created_at);
              t.setText (obj.getString("created_at"));
          } catch (JSONException e) {
  
              Log.e("alatta", e.getMessage());
          }
          return tv;
      }
  
     }
  </code></pre>
  
  <p><strong>ActiveHelper</strong></p>
  
  <pre><code> public class ActiveHelper {
  
  private static final String ACTIVE_SEARCH = "http://api.amp.active.com/search?&amp;v=json&amp;api_key=rm4agnjv6k4m4tvpft95xvbn";
      private static final int HTTP_STATUS_OK = 200;
      private static byte[] buff = new byte[1024];
  
  
  
   public static class SearchException extends Exception {
          public SearchException (String msg)
          {
              super (msg);
          }
  
          public SearchException (String msg, Throwable thr)
          {
              super (msg, thr);
          }
   }
          protected static synchronized String download (String parm)
                  throws SearchException
              {
                  String url = ACTIVE_SEARCH+ parm;
                  HttpClient client = new DefaultHttpClient();
                  HttpGet request = new HttpGet(url);
                  try {
                      HttpResponse response = client.execute(request);
                      StatusLine status = response.getStatusLine();
                      if (status.getStatusCode() != HTTP_STATUS_OK)
                          throw new SearchException("Invalid response from search.active.com" + 
                                  status.toString());
                      HttpEntity entity = response.getEntity();
                      InputStream ist = entity.getContent();
                      ByteArrayOutputStream content = new ByteArrayOutputStream();
                      int readCount = 0;
                      while ((readCount = ist.read(buff)) != -1)
                          content.write(buff, 0, readCount);
                      return new String (content.toByteArray());
                  } catch (Exception e) {
                      e.printStackTrace();
                      throw new SearchException("Problem using the API", e);
                  }
              }
          }
  </code></pre>
  
  <p><strong>StackTrace</strong></p>
  
  <pre><code>06-11 15:01:27.569: E/alatta(7698): Problem making search request
  06-11 15:01:27.569: W/System.err(7698): org.json.JSONException: End of input at character 0 of 
  06-11 15:01:27.569: W/System.err(7698):     at org.json.JSONTokener.syntaxError(JSONTokener.java:446)
  06-11 15:01:27.569: W/System.err(7698):     at org.json.JSONTokener.nextValue(JSONTokener.java:93)
  06-11 15:01:27.569: W/System.err(7698):     at org.json.JSONObject.&lt;init&gt;(JSONObject.java:154)
  06-11 15:01:27.569: W/System.err(7698):     at org.json.JSONObject.&lt;init&gt;(JSONObject.java:171)
  06-11 15:01:27.569: W/System.err(7698):     at my.stayactive.plan.StayActiveActivity$SearchTask.onPostExecute(StayActiveActivity.java:120)
  06-11 15:01:27.569: W/System.err(7698):     at my.stayactive.plan.StayActiveActivity$SearchTask.onPostExecute(StayActiveActivity.java:1)
  06-11 15:01:27.569: W/System.err(7698):     at android.os.AsyncTask.finish(AsyncTask.java:417)
  06-11 15:01:27.569: W/System.err(7698):     at android.os.AsyncTask.access$300(AsyncTask.java:127)
  06-11 15:01:27.579: W/System.err(7698):     at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:429)
  06-11 15:01:27.579: W/System.err(7698):     at android.os.Handler.dispatchMessage(Handler.java:99)
  06-11 15:01:27.579: W/System.err(7698):     at android.os.Looper.loop(Looper.java:150)
  06-11 15:01:27.579: W/System.err(7698):     at android.app.ActivityThread.main(ActivityThread.java:4293)
  06-11 15:01:27.579: W/System.err(7698):     at java.lang.reflect.Method.invokeNative(Native Method)
  06-11 15:01:27.579: W/System.err(7698):     at java.lang.reflect.Method.invoke(Method.java:507)
  06-11 15:01:27.579: W/System.err(7698):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:849)
  06-11 15:01:27.579: W/System.err(7698):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
  06-11 15:01:27.579: W/System.err(7698):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>