android - EditText SetText getting null value. Retrieving value via php from sql -


i've tried comes mind, i've researched 2 days now. new android. final cry turning masters on stackoverflow. guide me.

background.java

protected string doinbackground(string... params) {              string update_id = params[1];         try {             url url = new url(update_url);             httpurlconnection httpurlconnection = (httpurlconnection) url.openconnection();             httpurlconnection.setrequestmethod("post");             httpurlconnection.setdooutput(true);             outputstream os = httpurlconnection.getoutputstream();             bufferedwriter bufferedwriter = new bufferedwriter(new outputstreamwriter(os,"utf-8"));             string data = urlencoder.encode("id","utf-8") + "=" + urlencoder.encode(update_id, "utf-8");             os.write(data.getbytes());             bufferedwriter.flush();             os.close();             inputstream = httpurlconnection.getinputstream();             is.close();               bufferedreader bufferedreader = new bufferedreader(new inputstreamreader(url.openstream()));             string inputline;             while((inputline = bufferedreader.readline()) != null){                 sb.append(inputline);             }              return "update";}       @override           protected void onpostexecute(string result) {           accountdetailsfragment ac = new accountdetailsfragment();           ac.receivedetails(sb);} 

accountdetailsfragment.java

public class accountdetailsfragment extends fragment{  edittext update_id, update_address, update_name; string id = ""; string idd ,namee ,addresss, login_id; view v; public accountdetailsfragment() {     // required empty public constructor }  public void receiveloginid(string id){     this.login_id = id; }  public void receivedetails(stringbuilder sb){     string[] strarray = sb.tostring().split(pattern.quote("split"));     idd= strarray[0];     namee= strarray[1];     addresss= strarray[2];      system.out.println("-*-*--*-*-*-*-*-*-*-*");     system.out.println(idd);     system.out.println(namee);     system.out.println(addresss);     system.out.println("*-*-*-*-*-*-*-*-*-*-*");  }  @override public view oncreateview(layoutinflater inflater, viewgroup container,                          bundle savedinstancestate) {      layoutinflater lf = getactivity().getlayoutinflater();     v = lf.inflate(r.layout.fragment_account_details, container, false);      update_id = (edittext) v.findviewbyid(r.id.et_id_edit);     update_name = (edittext) v.findviewbyid(r.id.et_name_edit);     update_address = (edittext) v.findviewbyid(r.id.et_address_edit);      getactivity().settitle("account details");      button update = (button) v.findviewbyid(r.id.btnupdate);     update.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {              string method = "update";             background background = new background(getcontext());             background.execute(method, login_id);              system.out.println("*/*/*/*/*/*/*/*/*/*/*/");             system.out.println(idd);             system.out.println(namee);             system.out.println(addresss);             system.out.println("*/*/*/*/*/*/*/*/*/*/*/");              update_id.settext(idd.tostring());             update_name.settext(namee.tostring());             update_address.settext(addresss.tostring());          }     });      return v; }} 

update.php

<?php        require "init.php";      $update_id=$_post["id"];       $sql_query="select * test id = '$update_id'";       $result = mysqli_query($con,$sql_query);      if ($result->num_rows > 0) {     // output data of each row     while($row = $result->fetch_assoc()) {        echo $row["id"];        echo ("split");        echo $row["name"];        echo ("split");        echo $row["address"];    }    } else {         echo $update_id;    }   ?> 

logcat

i/system.out: */*/*/*/*/*/*/*/*/*/*/ 07-25 15:55:09.367 5914-5914/com.syntillate.aazif.aazifapp i/system.out: null 07-25 15:55:09.367 5914-5914/com.syntillate.aazif.aazifapp i/system.out: null 07-25 15:55:09.367 5914-5914/com.syntillate.aazif.aazifapp i/system.out: null 07-25 15:55:09.367 5914-5914/com.syntillate.aazif.aazifapp i/system.out:  */*/*/*/*/*/*/*/*/*/*/  java.lang.nullpointerexception: attempt invoke virtual method 'java.lang.string java.lang.string.tostring()' on null object reference                                                                                @ com.syntillate.aazif.aazifapp.accountdetailsfragment$1.onclick(accountdetailsfragment.java:115) 

change onpostexecute() this

@override protected void onpostexecute(string result) { receivedetails(sb); }

and make background inner class if it's not already.

you doing this:

accountdetailsfragment ac = new accountdetailsfragment(); ac.receivedetails(sb);

creating new instance of accountdetailsfragment , calling receivedetails() doesn't change values ( idd,namee & addresss) in calling class.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -