0

i'm getting this exception, but i don't understand why, my application have run very well until today, and i don't insert any changes on the http request for the server.

this is my code:

protected ArrayList<String> doInBackground(Void... params) {
        result = null;
        inputStream = null;
        ArrayList<String> person = new ArrayList<String>();
        try {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(url[0]);
            ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            nameValuePairs.add(new BasicNameValuePair("userName", LoginFragment.getUserName()));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            inputStream = entity.getContent();
        } catch (Exception exception) {
            Log.e("retrieve persons", "Error in http connection " + exception.toString());
        }

        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream), 8192);
            StringBuilder sb = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                sb.append(line + "\n");
            }
            inputStream.close();
            reader.close();
            result = sb.toString();
        } catch (Exception e) {
            Log.e("Error", "Error converting result " + e.toString());
        }
        if (!result.contains("null")) {
            try {
                JSONArray jArray = new JSONArray(result);
                for (int i = 0; i < jArray.length(); i++) {
                    JSONObject tuple = jArray.getJSONObject(i);
                    person.add(tuple.getString("name"));
                }
            } catch (JSONException e) {
                Log.e("Parser Problem", e.toString());
            }
        }
        return person;
    }

my logcat:

 E/Parser Problem(7078): org.json.JSONException: End of input at character 0 of 

i repeat, this function worked until yesterday,is it possible a side-server problem?

thanks in advance.

Yokupoku Maioku
  • 493
  • 7
  • 21
  • possible duplicates of http://stackoverflow.com/questions/22691406/error-parsing-data-org-json-jsonexception-end-of-input-at-character-0-of , http://stackoverflow.com/questions/23170610/error-parsing-data-org-json-jsonexception-end-of-input-at-character-0-of and http://stackoverflow.com/questions/8202048/org-json-json-exception-end-of-input-at-character-0 so on.. – Piyush Sep 18 '14 at 10:47
  • try to print your response string i.e. result and check if it is valid json or not. I think it due to changed reponse. – Beena Sep 18 '14 at 10:56
  • i tried to print result, and it is neither null nor strings form the server. – Yokupoku Maioku Sep 18 '14 at 10:57
  • Is it valid json response from your server? check out it on http://jsonviewer.stack.hu/ – Beena Sep 18 '14 at 10:59
  • i don't know this, what i have to insert? the URL? – Yokupoku Maioku Sep 18 '14 at 11:12

1 Answers1

0

First print "result" in a Logs and check whether its a valid JSON or not. You can use http://jsonformatter.curiousconcept.com/ to check that. Just copy the result string in the Editbox given on website and click on Validate.

Mahesh
  • 341
  • 2
  • 8
  • the string result, don't contains anything. i printed this: `Log.e("error","string " + result); ` and output was -> `error string , ` without the result, that is weird, seems like a server-side error, because before this function worked. – Yokupoku Maioku Sep 18 '14 at 13:38
  • This might be the reason for the JSONException. So first check why you are getting empty from server. Also change that condition of your code if (!result.contains("null")) to if(!TextUtils.isEmpty(result)) – Mahesh Sep 19 '14 at 13:30