android - probleme with AsyncTask: execute -


i tried use asynctask object connect application remote server. here's code:

public class connectserver extends asynctask<void, void, void> {      string ip = "";     inputstream = null;     jsonobject json_data = null;     arraylist<namevaluepair> namevaluepairs = new arraylist<namevaluepair>();     arraylist<string> donnees = new arraylist<string>();      @override     protected void doinbackground( void... params ) {          // todo auto-generated method stub         ip = "http://192.168.101.1/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();             = 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 try call start task, in onclick() method, this:

public void onclick( view v ) {      // todo auto-generated method stub     connectserver cs = new connectserver();      cs.execute( (void) null ); } 

it doesn't work. debug eclipse, sure error come line:

cs.execute((void)null); 

i try replace

cs.execute(); 

but error persists. debbuger gives me like:

thread [<10> asynctask #1] (suspended (exception runtimeexception))      threadpoolexecutor.runworker(threadpoolexecutor$worker) line: 1086       threadpoolexecutor$worker.run() line: 561        thread.run() line: 1096  thread [<12> asynctask #2] (running) 

i want add code works when use without asynctask.

try in connectserver class:

@override protected void onpostexecute(void result) {     toast.maketext(getapplicationcontext(), "fin d'envoi", >toast.length_short).show(); } 

try in activity:

@override public void onclick(view v) {    connectserver cs = new connectserver();    cs.execute(); } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -