final String message[] = {“”,””,””};
try{
String UID = null, UBAL = null;
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Calendar PDate;
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("UserID",id.getId()));
response = connection.executeHttpPost("http://condoproject.net16.net/PayCheck.php", postParameters);
Toast.makeText(getApplicationContext(), ""+response, Toast.LENGTH_LONG).show();
JSONArray jArray = new JSONArray(response);
for(int i = 0; i<jArray.length();i++)
{
JSONObject json_data= (JSONObject) jArray.get(i);
Toast.makeText(getApplicationContext(), ""+json_data, Toast.LENGTH_LONG).show();
UID = json_data.getString("UserID");
UBAL = json_data.getString("UPayment");
Uid1.setText(UID);
ubal.setText(UBAL);
PDate = (Calendar) json_data.get("PayDate");
PDate.add(Calendar.MONTH, 1);
String P = ""+PDate;
Udate.setText(P);
}
the UserID and the Balance are able to be display, but only for the date textview is empty. May I know the solution for this?
This is probably wrong:
First, I doubt casting from JSONObject to Calendar works this way. “Values may be any mix of JSONObjects, other JSONArrays, Strings, Booleans, Integers, Longs, Doubles, null or NULL. Values may not be NaNs, infinities, or of any type not listed here.” (here)
Try:
Second, you can’t get a date in human readable format this way:
If you want to add something to your date, you have to convert and convert back, for example:
if you only add one month to PDate to compensate for the fact that it stores month values from 0 to 11, then you can just do as Dheeraj said