0

I have an Asynch server call that is being made and every once in a while it generates this exception:

End of input at character 0 of

which I get here:

    @Override
    protected String doInBackground(String... theParams) 
    {
        String myUrl = theParams[0];
        final String user_id = theParams[1];

        String charset = "UTF-8";           
        String response = null;

        try 
        {                           
            String query = String.format("user_id=%s", 
                     URLEncoder.encode( user_id, charset) );

            final URL url = new URL( myUrl + "?" + query );

            final HttpURLConnection conn = (HttpURLConnection) url.openConnection();

            conn.setDoOutput(true); 
            conn.setRequestMethod("POST");

            conn.setDoOutput(true);
            conn.setUseCaches(false);

            conn.connect();

            final InputStream is = conn.getInputStream();
            final byte[] buffer = new byte[8196];
            int readCount;
            final StringBuilder builder = new StringBuilder();
            while ((readCount = is.read(buffer)) > -1) 
            {
                builder.append(new String(buffer, 0, readCount));
            }

            response = builder.toString();      
        } 
        catch (Exception e) 
        {
                 e.getMessage());
        }}

Would anyone know why that gets generated? Is it just the server being unresponsive? Or something else?

Thanks!

Genadinik
  • 18,153
  • 63
  • 185
  • 284
  • which line exactly throws it? – Marcin Orlowski Sep 26 '12 at 14:10
  • @WebnetMobile.com actually I wasn't able to get the exact line from the logs. – Genadinik Sep 26 '12 at 14:12
  • @genadik: Plant `Log.i("x")`; in **each** line of suspected code block, with "x" being unique string each time, so when exception is thrown you can trace what was the last `Log.i()` executed. Then you know where exactly it was thrown. – Marcin Orlowski Sep 26 '12 at 14:15
  • @WebnetMobile.com I can not reproduce this problem during testing - it just happens randomly for some users. Is it possible to get the usage log from my users? I have not looked into that. – Genadinik Sep 26 '12 at 14:19

1 Answers1

0

This question has been asked before.

Are you sure you aren't making a POST request to an url that is expecting a GET? Try changing that requestMethod to GET and see how it goes.

Check this question out:

org.json.JSON Exception : End of input at character 0

Community
  • 1
  • 1
DallaRosa
  • 5,737
  • 2
  • 35
  • 53
  • I am not certain of get/post but this code works 98% of the time...I am just not sure why sometimes it does this. – Genadinik Sep 26 '12 at 14:13