Android inserting value in database in background -
i using asyntask enter value in database. in in backgroud method calling method.
private void calllogin() { getdatafromapi getdatafromapi = new getdatafromapi(url); if (!istablefalse) { log.e("mai gaaya syncronise data base mai", "ha mai aya"); string message = getdatafromapi.postsignin().tostring().trim(); syncronisedatabase(message); populatechurchlistonvalidating .populatechurchlist(parsejsontoarraylist()); } else { try { loginvalue = integer.parseint(getdatafromapi.postsignin()); log.e("login value", "" + loginvalue); } catch (numberformatexception nfe) { nfe.printstacktrace(); } } }
and syncronisedatabase(message) this
private void syncronisedatabase(string messtring) {
log.e("url in syncronisation", ""+ url);
try { inserttable inserttable = new inserttable(); jsonobject jsonobject = new jsonobject(messtring); inserttable.addrowformembertable(jsonobject.getstring( registrationappconstant.member_id), jsonobject.getstring(registrationappconstant.client_id), jsonobject.getstring(registrationappconstant.firstname), jsonobject.getstring(registrationappconstant.surname), jsonobject.getstring(registrationappconstant.email_id), jsonobject.getstring(registrationappconstant.password)); log.e("inserting data done", "" + "done"); } catch (jsonexception e) { // todo auto-generated catch block e.printstacktrace(); } }
and class forinserttable this
public class inserttable { public void addrowformembertable(string memberid, string clientid, string firstname,string surname, string emailidstring, string passwordstring) { log.e("name", "" + memberid + " " + clientid + " " + firstname + " " + surname + " " + emailidstring + " " + passwordstring); contentvalues contentvalue = new contentvalues(); contentvalue.put(appconstant.mcm_member_memeber_id, memberid); contentvalue.put(appconstant.mcm_member_client_id, clientid); contentvalue.put(appconstant.mcm_member_first_name, firstname); contentvalue.put(appconstant.mcm_member_last_name, surname); contentvalue.put(appconstant.mcm_member_email_id, emailidstring); contentvalue.put(appconstant.mcm_member_password, passwordstring); log.e("cotent value", "" + contentvalue); try { splashactivity.databasehelper.insertintotable( splashactivity.databasehelper.getwritabledatabase(), appconstant.member_table_name, contentvalue); } catch (exception e) { e.printstacktrace(); } } }
this json string
[{"memberid":77,"clientid":37,"firstname":"john","surname":"banian","address1":null,"address2":null,"street":null,"town":null,"city":null,"county":null,"state":null,"country":null,"postcode":null,"mobile":null,"hometelephone":null,"worktelephone":null,"emailid":"jbunian@yahoo.com","confirmemailid":null,"password":"123","age":null,"sex":null,"profession":null,"martialstatus":null,"nationality":null,"children":null,"churchmembershipid":null,"securityquestion":null,"securityanswer":null,"isapproved":null,"islockedout":null,"createdate":null,"lastlogindate":null,"lastpasswordchangeddate":null,"lastlogoutdate":null,"failedpasswordattemptdate":null,"failedpasswordattemptwindowstart":null,"failedpasswordanswerattemptcount":null,"failedpasswordanswerattemptwindowstart":null,"comment":null,"active":null,"isauthtoapprovenewmember":null,"record_created":null,"record_updated":null,"lastupdated_loginuserid":null,"lastupdated_windowsuser":null,"clientadminemailid":null,"emaillistforapproval":null,"appregistrationstatus":null,"memberemailmessage":null,"adminemailmessage":null,"physicaldeviceid":null,"deviceos":null,"deviceidfromgcmorapns":null,"devicetype":null}]
but code not executing after line , hence not able insert value.i have bold log after not executing.please tell why not executing?
problem tring values jsonobject, in reality it's json array. (json string starts [.
try this:
jsonarray jsonarray = new jsonarray(messtring); jsonobject jsonobject = jsonarray.get(0); inserttable.addrowformembertable(jsonobject.getstring(registrationappconstant.member_id), jsonobject.getstring(registrationappconstant.client_id), ..... .....
Comments
Post a Comment