java - Android Fatal Error: Async Task


Hey I am having a problem with my application that I can't resolve, I tryed everything I knew about Async Task but I am not good at it.


03-17 19:43:38.794    1662-1681/com.cwpsiproject E/AndroidRuntime﹕ FATAL EXCEPTION: AsyncTask #5
    java.lang.RuntimeException: An error occured while executing doInBackground()
            at android.os.AsyncTask$3.done(
            at java.util.concurrent.FutureTask.finishCompletion(
            at java.util.concurrent.FutureTask.setException(
            at android.os.AsyncTask$SerialExecutor$
            at java.util.concurrent.ThreadPoolExecutor.runWorker(
            at java.util.concurrent.ThreadPoolExecutor$
     Caused by: java.lang.IllegalArgumentException: Illegal character in query at index 72: AW&consola=Xbox One
            at org.apache.http.client.methods.HttpGet.<init>(
            at com.cwpsiproject.ApiConnector.createTeam(
            at com.cwpsiproject.CreateTeamActivity$createTeamTask.doInBackground(
            at com.cwpsiproject.CreateTeamActivity$createTeamTask.doInBackground(
            at android.os.AsyncTask$
            at android.os.AsyncTask$SerialExecutor$
            at java.util.concurrent.ThreadPoolExecutor.runWorker(
            at java.util.concurrent.ThreadPoolExecutor$

Code CreateTeamTask:

    private class createTeamTask extends AsyncTask<ApiConnector,Long,JSONArray> {
        protected JSONArray doInBackground(ApiConnector... params) {
            // it is executed on Background thread
            String teamName = f.getTeamNameC(); // returns string with teamName
            String game = f.getGameC(); // returns string with game
            String consola = f.getConsoleC(); // returns string with console
            return params[0].createTeam(teamName, game, consola);
        protected void onPostExecute(JSONArray jsonArray) {
            Toast.makeText(CreateTeamActivity.this, "Team Successfully Created!", Toast.LENGTH_SHORT).show();

ApiConnector code:

public JSONArray createTeam(String teamName, String game, String consola) {
    String url = ""+teamName+"&game="+game+"&consola="+consola;
    // Get HttpResponse Object from url.
    // Get HttpEntity from Http Response Object
    HttpEntity httpEntity = null;
    try {
        DefaultHttpClient httpClient = new DefaultHttpClient();  // Default HttpClient
        HttpGet httpGet = new HttpGet(url);
        HttpResponse httpResponse = httpClient.execute(httpGet);
        httpEntity = httpResponse.getEntity();
    } catch (ClientProtocolException e) {
        // Signals error in http protocol
        //Log Errors Here
    } catch (IOException e) {
    // Convert HttpEntity into JSON Array
    JSONArray jsonArray = null;
    if (httpEntity != null) {
        try {
            String entityResponse = EntityUtils.toString(httpEntity);
            Log.e("Entity Response  : ", entityResponse);
            jsonArray = new JSONArray(entityResponse);
        } catch (JSONException e) {
        } catch (IOException e) {
    return jsonArray;


    include 'connection.php';

    if (isset($_GET['teamName']) && isset($_GET['game']) && isset($_GET['consola'])) {
                $teamName = $_GET['teamName'];
                $game = $_GET['game'];
                $consola = $_GET['consola'];
                $teamName = mysql_real_escape_string($teamName);
                $game = mysql_real_escape_string($game);
                $consola = mysql_real_escape_string($consola);

        mysql_query("INSERT INTO `team_data` (`teamName`, `game`, `console`) VALUES('$teamName','$game','$consola')");



Can someone please help me with this? I am stuck at this error, the funny thing is that I have almost the same code for registering the user and it doesn't give this error.

thanks for the time.




You have illegal characters in your Url (mainly the spaces, and colon), you need to make sure you're using correct url encoding. An easy way to accomplish this, would be to use Uri.Builder() to build your URL.


In your exception, it shows the following URL throws the error: " AW&consola=Xbox One". Note that even as displayed here, the first illegal character breaks the hyperlink.

To sanitize this Url, you need to append the query parameters correctly, for example using the above url:

    Uri.Builder builder = Uri.parse("").buildUpon();
        builder.appendQueryParameter("teamName", "vcxvxcvcxvxcvxc");
        builder.appendQueryParameter("game", "COD: AW");
        builder.appendQueryParameter("consola", "Xbox One");

    String url =;

The result:

People are also looking for solutions to the problem: php - One cURL connection not working, but the second one is


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.