0

My async function is this:

class ProfileCategoryCall extends AsyncTask<String, String, String>{
        public ProfileCategoryCall() {
            // TODO Auto-generated constructor stub
        }

        @Override
        protected String doInBackground(String... uri) {
            HttpClient httpclient = new DefaultHttpClient();
            HttpResponse response;
            String responseString = null;
            try {
                response = httpclient.execute(new HttpGet(uri[0]));
                StatusLine statusLine = response.getStatusLine();
                if(statusLine.getStatusCode() == HttpStatus.SC_OK){
                    ByteArrayOutputStream out = new ByteArrayOutputStream();
                    response.getEntity().writeTo(out);
                    out.close();
                    responseString = out.toString();
                } else{
                    //Closes the connection.
                    response.getEntity().getContent().close();
                    throw new IOException(statusLine.getReasonPhrase());
                }
            } catch (ClientProtocolException e) {
                //TODO Handle problems..
            } catch (IOException e) {
                //TODO Handle problems..
            }
            return responseString;
        }

        @Override
        protected void onPostExecute(String result) {
            JSONObject HomeCardString = new JSONObject();
            JSONObject ABC = new JSONObject();
            try {
                responseString = result;
                joiningYear = new JSONObject(responseString);
                HomeCardString = joiningYear.getJSONObject("CategoryLikesResult");
                ABC = HomeCardString.getJSONObject("CategoryLikesResult");      
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            try {       
                Gson gson = new Gson();
                try
                {
                    ((ProfileActivity)getActivity()).interestResult = gson.fromJson(ABC.toString(), LikeCategorySummaryResult.class);

                }
                catch(Exception e)
                {
                    Log.i("myyyy", e.getMessage());
                    e.printStackTrace();
                }

            } catch (Throwable t) {
                Log.e("My App", "Could not parse malformed JSON: \"" + responseString + "\"" + t.getMessage());
            }

            PopulateData();

            progress.setVisibility(View.GONE);          
            super.onPostExecute(result);
            //Do anything with response..
        }

        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            progress.setVisibility(View.VISIBLE);
            super.onPreExecute();
        }
    }

While Calling async service call this error occurs.

08-28 11:15:38.140: E/AndroidRuntime(14310): FATAL EXCEPTION: AsyncTask #1
    08-28 11:15:38.140: E/AndroidRuntime(14310): java.lang.RuntimeException: An error occured while executing doInBackground()
    08-28 11:15:38.140: E/AndroidRuntime(14310):    at android.os.AsyncTask$3.done(AsyncTask.java:278)
    08-28 11:15:38.140: E/AndroidRuntime(14310):    at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
    08-28 11:15:38.140: E/AndroidRuntime(14310):    at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
    08-28 11:15:38.140: E/AndroidRuntime(14310):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
    08-28 11:15:38.140: E/AndroidRuntime(14310):    at java.util.concurrent.FutureTask.run(FutureTask.java:137)
    08-28 11:15:38.140: E/AndroidRuntime(14310):    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
    08-28 11:15:38.140: E/AndroidRuntime(14310):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
    08-28 11:15:38.140: E/AndroidRuntime(14310):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
    08-28 11:15:38.140: E/AndroidRuntime(14310):    at java.lang.Thread.run(Thread.java:856)
    08-28 11:15:38.140: E/AndroidRuntime(14310): Caused by: java.lang.IllegalArgumentException: Illegal character in query at index 355: http://example.net/Service.svc/android/Profile/1361769105/Like/EXAMPLE?category=Public
    08-28 11:15:38.140: E/AndroidRuntime(14310):    at java.net.URI.create(URI.java:727)
    08-28 11:15:38.140: E/AndroidRuntime(14310):    at org.apache.http.client.methods.HttpGet.<init>(HttpGet.java:75)
    08-28 11:15:38.140: E/AndroidRuntime(14310):    at com.stalker.androidapp.InterestTabFragment$ProfileCategoryCall.doInBackground(InterestTabFragment.java:308)
    08-28 11:15:38.140: E/AndroidRuntime(14310):    at com.stalker.androidapp.InterestTabFragment$ProfileCategoryCall.doInBackground(InterestTabFragment.java:1)
    08-28 11:15:38.140: E/AndroidRuntime(14310):    at android.os.AsyncTask$2.call(AsyncTask.java:264)
    08-28 11:15:38.140: E/AndroidRuntime(14310):    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
    08-28 11:15:38.140: E/AndroidRuntime(14310):    ... 5 more

I have seen other similar questions, but answers were to remove code which is using UI from doInBackground() and I don't think I have any unnecessary code in it. So please tell me if I am wrong.

Subburaj
  • 5,114
  • 10
  • 44
  • 87
Yawar
  • 1,924
  • 3
  • 29
  • 39
  • 1
    Illegal character in query at index 355 check InterestTabFragment.java:308 – Michael Shrestha Aug 28 '14 at 06:43
  • 1
    Your error shows: "Caused by: java.lang.IllegalArgumentException: Illegal character in query at index 355: http://example.net/Service.svc/android/Profile/1361769105/Like/EXAMPLE?category=Public"..Check your URI.. – Subburaj Aug 28 '14 at 06:44
  • 1
    what is the point of throwing an exception if you end up just catching it , Log the reasonPhrase instead – Lena Bru Aug 28 '14 at 06:47
  • 2
    You should escape your characters in the uri. http://stackoverflow.com/a/4571518/1137118 – Pphoenix Aug 28 '14 at 06:48
  • All your answers helped me a lot, I don't know why it is appending string with my URL at the end with a space bar which is creating problem. Now I have to figure it out. – Yawar Aug 28 '14 at 07:10

0 Answers0