String name;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getData();
this.setText(name);
}
private void getData(){
name = object.getString("name");
}
I'm just making my line of code short, anyway the idea is already there. So on the method getData()
I'm retrieving data from the web. I am able to test and was able to get the result however when I put the name on the onCreate()
it gives me a null value. How to do some work arounds on this?
public class Testing extends NavigationLiveo{
String name;
@Override
public void onInt(Bundle savedInstanceState) {
getData();
Log.wtf("name0", name);
this.username.setText(name);
}
private void getData() {
RequestQueue queue = Volley.newRequestQueue(getApplicationContext());
StringRequest sr = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
@Override
public void onResponse(String s) {
try {
name = object.getString("name");
Log.wtf("name1", name);
} catch (Exception e) {
Log.wtf("testing1", e.getMessage());
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> params = new HashMap<String, String>();
params.put("user", user_pid);
return params;
}
};queue.add(sr);
}
}
Once again, I've made my coding simple. I can really get the data from the web server. It's just that whenever the I'll try to access the name on the onInt(Bundle savedInstanceState) it returns a null value. The log says it all as well. "name1" returns a value while "name0" returns null.