Java JSONException: End of input at character 0 of


This Content is from Stack Overflow. Question asked by Usman Adam

I am trying to get JSON object from OpenSubtitles API. I don’t know what is wrong with my code. I am using OkHttpClient and here is my code in below


   new Thread(new Runnable() {                                                                                              
   public void run() {  
       OkHttpClient client = new OkHttpClient();                                                                        
       MediaType mediaType = MediaType.parse("application/json");                                                       
       RequestBody body = RequestBody.create(mediaType, "{n  "file_id": file_idn}");                                
       Request request = new Request.Builder()                                                                          
               .addHeader("Content-Type", "application/json")                                                           
               .addHeader("Api-Key", "Api-Key")                                                
       try {      
           Response response = client.newCall(request).execute();                                                       
           /// get date from your response                                                                              
           String responseBody = response.body().string();                                                              
           ///// convert it to json object                                                                              
           JSONObject jsonObject = new JSONObject(responseBody);                                                        
           Log.d("DATA: ", String.valueOf(jsonObject)); // this is where i get the error            
       } catch (IOException e) {                                                                                        
           Log.d("IO EXCEPTION", "TIMEOUT");                                                                       
       } catch (Exception e) {                                                                                          
           Log.d("OTHER EXCEPTION", "OTHER EXCEPTION");                                                                 



  "link": "",
  "file_name": "",
  "requests": 6,
  "remaining": 94,
  "message": "Your quota will be renewed in 21 hours and 44 minutes (2022-09-19 23:16:46 UTC) ",
  "reset_time": "21 hours and 44 minutes",
  "reset_time_utc": "2022-09-19T23:16:46.000Z"



W/System.err: org.json.JSONException: End of input at character 0 of 
W/System.err:     at org.json.JSONTokener.syntaxError(
W/System.err:     at org.json.JSONTokener.nextValue(
W/System.err:     at org.json.JSONObject.<init>(
W/System.err:     at org.json.JSONObject.<init>(
W/System.err:     at com.nomedia.restapi.MainActivity$
W/System.err:     at


I tried adding my token to header but it still show the same error

Thanks for your input


This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?