I probably have a problem with my Object but I've not figure it out yet.
The issue here is: everytime I want to set text my textViewHoTen to nguoiDung.getAnything(), my app will stop working. I can set it by another Strings but not with Strings from nguoiDung.
I'm trying many things, my ways found online but not thing work either.
Here is part of my app. Hope someone could me out. Thank you.
1. Class NguoiDung
public class NguoiDung {
public String username;
public String email;
public String password;
public String ho;
public String ten;
public String sodienthoai;
//Constructor
public NguoiDung(String username, String email, String password, String ho, String ten, String sodienthoai) {
this.username = username;
this.email = email;
this.password = password;
this.ho = ho;
this.ten = ten;
this.sodienthoai = sodienthoai;
}
//Getter Setter
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getHo() {
return ho;
}
public void setHo(String ho) {
this.ho = ho;
}
public String getTen() {
return ten;
}
public void setTen(String ten) {
this.ten = ten;
}
public String getSodienthoai() {
return sodienthoai;
}
public void setSodienthoai(String sodienthoai) {
this.sodienthoai = sodienthoai;
}
}
2. My Fragment generally have
NguoiDung nguoiDung;
textViewHoTen = (TextView) V.findViewById(R.id.textViewHoTen);
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
inflater = getActivity().getLayoutInflater();
View V = inflater.inflate(R.layout.tab_tai_khoan_view, container, false);
getData(V, url);
textViewHoTen = (TextView) V.findViewById(R.id.textViewHoTen);
textViewHoTen.setText(nguoiDung.getUsername());
return V;
}
3.getData()
private void getData(View V, String url){
RequestQueue requestQueue = Volley.newRequestQueue(V.getContext());
JsonArrayRequest jsonArrayRequest = new JsonArrayRequest(Request.Method.GET, url, null,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
for (int i=0; i<response.length(); i++){
try {
JSONObject object = response.getJSONObject(i);
nguoiDung = new NguoiDung(
object.getString("Username"),
object.getString("Email"),
object.getString("Password"),
object.getString("Ho"),
object.getString("Ten"),
object.getString("SoDienThoai")
);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}
);
requestQueue.add(jsonArrayRequest);
}