can't connect android app to mysql using php the error is with my android code -


import android.os.bundle;  import android.app.activity; import android.view.menu; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import java.io.ioexception; import java.io.unsupportedencodingexception; import java.util.arraylist; import java.util.list;  import org.apache.http.httpentity; import org.apache.http.httpresponse; import org.apache.http.namevaluepair; import org.apache.http.client.clientprotocolexception; import org.apache.http.client.httpclient; import org.apache.http.client.entity.urlencodedformentity; import org.apache.http.client.methods.httppost; import org.apache.http.impl.client.defaulthttpclient; import org.apache.http.message.basicnamevaluepair;    import android.os.strictmode; import android.util.log; import android.widget.edittext;  public class login extends activity { button button2;  @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_login); edittext breakfast= (edittext)  findviewbyid(r.id.breakfast) ;         edittext lunch = (edittext) findviewbyid(r.id.lunch);         edittext dinner = (edittext) findviewbyid(r.id.dinner);         edittext supper = (edittext) findviewbyid(r.id.supper);         button button = (button) findviewbyid(r.id.button1) ;          final string breakf = breakfast.gettext().tostring();         final string lun = lunch.gettext().tostring();         final string din = dinner.gettext().tostring();         final string sup = supper.gettext().tostring(); button2=(button)this.findviewbyid(r.id.button2); button2.setonclicklistener(new onclicklistener() { @override public void onclick(view arg0) {    // generate params:    list<namevaluepair> namevaluepairs = new arraylist<namevaluepair>();    namevaluepairs.add(new basicnamevaluepair("breakfast", breakf));    namevaluepairs.add(new basicnamevaluepair("lunch", lun));    namevaluepairs.add(new basicnamevaluepair("dinner", din));    namevaluepairs.add(new basicnamevaluepair("supper", sup));     // send them on way    try {        defaulthttpclient httpclient = new defaulthttpclient();         httppost httppost = new httppost("http://blahblah php?$username=caroline$password=scamper"); 

i have proper url blanked out

      // httppost.setentity(new urlencodedformentity(namevalueparams));         httpresponse httpresponse = httpclient.execute(httppost);        httpentity httpentity = httpresponse.getentity();     } catch (unsupportedencodingexception e) {        e.printstacktrace();    } catch (clientprotocolexception e) {        e.printstacktrace();    } catch (ioexception e) {        e.printstacktrace();    } }});} //@override         public void onclick(view v) { finish(); system.exit(0); } }); intent intent = new intent(login.this, .class); login.this.startactivity(intent); //new lister save start db code //take info button sql        @override    public void onclick(view arg0) {        // todo auto-generated method stub        postdata(); });     // }  @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; }  

i know have errors in have been changeig , can't figure why won't change appreiciated php should work not getting info app

you shouldn't invoke network connections in main thread. try using asynctask in order run network operations on background thread.

try this

class login extends activity {    protected void oncreate(bundle savedinstancestate)     {      button2.setonclicklistener(new onclicklistener()       {        public void onclick(view arg0)         {          task t = new task();          t.execute();        }    }    class task extends asynctask<argtype,argtype,argtype>    {      protected type doinbackground(argtype... urls)       {        try        {           //initiate httpconnection , result        }        catch        {        }      }      protected void onpostexecute(argtype result)       {        //update view or thing when background thread work done      }    } } 

or can refer http://www.android-ever.com/2012/10/android-asynctask-example.html more information on asynctask.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -