Title: probleme with AsyncTask: execute
Tags: android;android-asynctask;execute
Question: I tried to use ```AsyncTask``` object to connect my application to a remote server.
Here's my code:

```public class ConnectServer extends AsyncTask<Void, Void, Void&gt; {

    String IP = "";
    InputStream is = null;
    JSONObject json_data = null;
    ArrayList<NameValuePair&gt; nameValuePairs = new ArrayList<NameValuePair&gt;();
    ArrayList<String&gt; donnees = new ArrayList<String&gt;();

    @Override
    protected Void doInBackground( Void... params ) {

        // TODO Auto-generated method stub
        IP = "http://(816)671-1913/fichier.php";
        nameValuePairs.add( new BasicNameValuePair( "nom", envois.nom ) );
        nameValuePairs.add( new BasicNameValuePair( "prenom", envois.prenom ) );
        nameValuePairs.add( new BasicNameValuePair( "nationalite", envois.nationalite ) );
        nameValuePairs.add( new BasicNameValuePair( "passeport", envois.passeport ) );

        try {
            //commandes httpClient
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost( IP );
            httppost.setEntity( new UrlEncodedFormEntity( nameValuePairs ) );
            HttpResponse response = httpclient.execute( httppost );
            HttpEntity entity = response.getEntity();
            is = entity.getContent();
            Log.i( "tag", "depuis json" );
        }
        catch (Exception e) {
            Log.i( "taghttppost", "" + e.toString() );
            Toast.makeText( c, e.toString(), Toast.LENGTH_LONG ).show();
        }

        return null;
    }

    @Override
    protected void onPreExecute() {

        // TODO Auto-generated method stub
        super.onPreExecute();
    }

    @Override
    protected void onPostExecute( Void result ) {

        // TODO Auto-generated method stub
        super.onPostExecute( result );
        Toast.makeText( getApplicationContext(), "fin d'envoi", Toast.LENGTH_SHORT ).show();
    }
}
```

Then when i try to call start that task, in my ```onClick()``` method, like this:

```public void onClick( View v ) {

    // TODO Auto-generated method stub
    ConnectServer cs = new ConnectServer();

    cs.execute( (Void) null );
}
```

It doesn't work. I debug it with eclipse, i am sure that the error come from this line:

```cs.execute((Void)null);
```

I try to replace it by 

```cs.execute();
```

But the error persists. The debbuger gives me something like:

```Thread [<10&gt; AsyncTask #1] (Suspended (exception RuntimeException)) 
    ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker) line: 1086  
    ThreadPoolExecutor$Worker.run() line: 561   
    Thread.run() line: 1096 
Thread [<12&gt; AsyncTask #2] (Running)
```

I want to add that my code works perfectly when I use it without ```AsyncTask```.

Comment: Why do you have to strings for the ip, in the global variable you have it equal to nothing.

Comment: TheBluCat, i have just initialyze the IP, but that is not the problem, becauz it worked with this when i removed AsyncTask


Here is another answer: as it turns out sometimes just ```Project-&gt;Clean..``` in Eclipse will solve the problem.. ;)


Here is another answer: Try this in ConnectServer class:

```@Override
protected void onPostExecute(Void result) {
    Toast.makeText(getApplicationContext(), "fin d'envoi", &gt;Toast.LENGTH_SHORT).show();
}
```

Try this in the Activity:

```@Override
public void onClick(View v) {
   ConnectServer cs = new ConnectServer();
   cs.execute();
}
```

Comment for this answer: I think i need to precise that the onClick method is called in a Actvivty thread, not in ConnectServer
Comment for this answer: OK! today it works!  I don't why but it works,i didn't change anything,but suddently works :):):):) Thank u guys

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 2, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2012:00:06/04/12', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<android><android-asynctask><execute>', 'Title': 'probleme with AsyncTask: execute', 'ViewCount': 784, 'id': 10885818, 'user_AboutMe': '<p>Kind, courageous, worker, honnest.</p>\n', 'user_AccountId': 951582.0, 'user_DisplayName': 'sofo', 'user_Reputation': 103.0, 'user_Views': 17.0, 'user_id': 977632.0}}