title: org.json.JSONException: End of input at character 0
body: <p>I have been stuck on this for a while. Simply cannot figure out whats wrong. A pair of fresh eyes would be very helpful. I keep on getting the org.json.JSONException: End of input at character 0 of and cannot figure it out.</p>
  
  <p>My JSONParser</p>
  
  <pre><code> public JSONObject makeHttpRequest(String url, String method,
          List&lt;NameValuePair&gt; params) {
  
      // Making HTTP request
      try {
  
          // check for request method
          if(method == "POST"){
              // request method is POST
              // defaultHttpClient
              DefaultHttpClient httpClient = new DefaultHttpClient();
              HttpPost httpPost = new HttpPost(url);
              httpPost.setEntity(new UrlEncodedFormEntity(params));
  
              HttpResponse response = httpClient.execute(httpPost);
              String responseBody = EntityUtils.toString(response.getEntity());
              //HttpEntity httpEntity = httpResponse.getEntity();
              //is = httpEntity.getContent();
             JSONArray jsArray = new JSONArray(responseBody);
             JSONObject js = jsArray.getJSONObject(0);
             String returnvalmsg = js.getString("message");
             String returnvalsucc = js.getString("success");
  
          }else if(method == "GET"){
              // request method is GET
              DefaultHttpClient httpClient = new DefaultHttpClient();
              String paramString = URLEncodedUtils.format(params, "utf-8");
              url += "?" + paramString;
              HttpGet httpGet = new HttpGet(url);
  
              HttpResponse httpResponse = httpClient.execute(httpGet);
              HttpEntity httpEntity = httpResponse.getEntity();
              is = httpEntity.getContent();
          }          
  
      } catch (UnsupportedEncodingException e) {
          e.printStackTrace();
      } catch (ClientProtocolException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
     // } catch (JSONException e) {
          // TODO Auto-generated catch block
          //e.printStackTrace();
      } catch (JSONException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
      try {
          BufferedReader reader = new BufferedReader(new InputStreamReader(
                  is, "iso-8859-1"), 8);
          StringBuilder sb = new StringBuilder();
          String line = null;
  
  
          while ((line = reader.readLine()) != null) {
              sb.append(line + "\n");
          }
          is.close();
          json = sb.toString();
  
      } catch (Exception e) {
          Log.e("Buffer Error", "Error converting result " + e.toString());
      }
  
      // try parse the string to a JSON object
      try {
          jObj = new JSONObject(json);
      } catch (JSONException e) {
          Log.e("JSON Parser", "Error parsing data " + e.toString());
      }
  
      // return JSON String
      return jObj;
  
    }
  }
  </code></pre>
  
  <p>Activity</p>
  
  <pre><code>btnRegisterfine.setOnClickListener(new View.OnClickListener() {
  
                               @Override
                              public void onClick(View view) {
                                  // creating new product in background thread
                                  new CreateNewFine().execute();
                              }
  
  
                        });
      }
  
                        /**
                           * Background Async Task to Register Fine
                           * */
                          class CreateNewFine extends AsyncTask&lt;String, String, String&gt; {
  
                              /**
                               * Before starting background thread Show Progress Dialog
                               * */
                              @Override
                              protected void onPreExecute() {
                                  super.onPreExecute();
                                  pDialog = new ProgressDialog(Finecalc.this);
                                  pDialog.setMessage("Registering Fine..");
                                  pDialog.setIndeterminate(false);
                                  pDialog.setCancelable(true);
                                  pDialog.show();
                              }
  
                              /**
                               * Registering Fine
                               * */
                              protected String doInBackground(String... args) {
                                  String driver = inputDriver.getText().toString();
                                  String licencenum = inputLicence.getText().toString();
                                  String officer = inputOfficer.getText().toString();
                                  String speed = inputSpeed.getText().toString();
                                  String fine= FineAppl.getText().toString();
                                  String category = inputCategory.getText().toString();
  
  
                                  // Building Parameters
                                  List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
                                  params.add(new BasicNameValuePair("driver", driver));
                                  params.add(new BasicNameValuePair("licencenum", licencenum));
                                  params.add(new BasicNameValuePair("officer", officer));
                                  params.add(new BasicNameValuePair("speed", speed));
                                  params.add(new BasicNameValuePair("fine", fine));
                                  params.add(new BasicNameValuePair("category", category));
  
                                  // getting JSON Object
                                  // Note that create product url accepts POST method
                                  JSONObject json = jsonParser.makeHttpRequest(url_create_fine,
                                          "POST", params);
  
                                  // check log cat fro response
                                  Log.d("Create Response", json.toString());
  
                                  // check for success tag
                                  try {
                                      int success = json.getInt(TAG_SUCCESS);
  
                                      if (success == 1) {
                                          // successfully Registered Fine
                                          //Intent i = new Intent(getApplicationContext(), Finecalc.class);
                                          //startActivity(i);
                                          registerFine.setText("DONE");
                                          // closing this screen
                                          finish();
                                      } else {
                                          // failed to Register Fine
                                      }
                                  } catch (JSONException e) {
                                      e.printStackTrace();
                                  }
  
                                  return null;
                              }
  
                              /**
                               * After completing background task Dismiss the progress dialog
                               * **/
                              protected void onPostExecute(String file_url) {
                                  // dismiss the dialog once done
                                  pDialog.dismiss();
                              }
  
                          }
  </code></pre>
  
  <p>My Php</p>
  
  <pre><code>&lt;?php
  
  // array for JSON response
  $response = array();
  
  // check for required fields
  if (isset($_POST['driver'], $_POST['licencenum'], $_POST['officer'], $_POST['speed'] , $_POST['fine'],$_POST['category'])){
  
      $driver = $_POST['driver'];
   $licencenum = $_POST['licencenum'];
   $officer = $_POST['officer'];
      $speed = $_POST['speed'];
      $fine = $_POST['fine'];
      $category = $_POST['category'];
  
  
      // include db connect class
      require_once __DIR__ . '/db_connect.php';
  
      // connecting to db
      $db = new DB_CONNECT();
  
      // mysql inserting a new row
  $result = mysql_query("INSERT INTO fineregister(driver,licencenum,officer,speed,fine,category) VALUES   ('$driver','$licencenum','$officer','$speed','$fine',      '$category')");
  
      // check if row inserted or not
   if ($result) {
      // successfully inserted into database
      $response["success"] = 1;
      $response["message"] = "Speed Ticket Successfully Registered.";
  
      // echoing JSON response
      echo json_encode($response);
      } else {
      // failed to insert row
      $response["success"] = 0;
      $response["message"] = "Oops! An error occurred.";
  
      // echoing JSON response
      echo json_encode($response);
   }
  } else {
  // required field is missing
  $response["success"] = 0;
  $response["message"] = "Required field(s) is missing";
  
  // echoing JSON response
  echo json_encode($response);
  }
  ?&gt;
  </code></pre>
  
  <p>And my error:</p>
  
  <blockquote>
    <p>08-05 09:53:03.321: W/System.err(3072): org.json.JSONException: End of input at character 0 of 
    08-05 09:53:03.321: W/System.err(3072):     at org.json.JSONTokener.syntaxError(JSONTokener.java:450)
    08-05 09:53:03.321: W/System.err(3072):     at org.json.JSONTokener.nextValue(JSONTokener.java:97)
    08-05 09:53:03.331: W/System.err(3072):     at org.json.JSONArray.(JSONArray.java:92)
    08-05 09:53:03.331: W/System.err(3072):     at org.json.JSONArray.(JSONArray.java:108)
    08-05 09:53:03.331: W/System.err(3072):     at com.lta.fine.JSONParser.makeHttpRequest(JSONParser.java:60)
    08-05 09:53:03.341: W/System.err(3072):     at com.lta.fine.MainActivity$CreateNewFine.doInBackground(MainActivity.java:191)
    08-05 09:53:03.341: W/System.err(3072):     at com.lta.fine.MainActivity$CreateNewFine.doInBackground(MainActivity.java:1)
    08-05 09:53:03.351: W/System.err(3072):     at android.os.AsyncTask$2.call(AsyncTask.java:288)
    08-05 09:53:03.351: W/System.err(3072):     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    08-05 09:53:03.361: W/System.err(3072):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
    08-05 09:53:03.361: W/System.err(3072):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
    08-05 09:53:03.361: W/System.err(3072):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
    08-05 09:53:03.361: W/System.err(3072):     at java.lang.Thread.run(Thread.java:841)
    08-05 09:53:03.361: E/Buffer Error(3072): Error converting result java.lang.NullPointerException: lock == null
    08-05 09:53:03.371: E/JSON Parser(3072): Error parsing data org.json.JSONException: End of input at character 0 of </p>
  </blockquote>