I have 7 buttons. On the first button I display the current date, on the second button I want it to display the date of tomorrow, on the third one the date after that, and so on.
I tried several times using Calendar
but the app close when this activity open. can someone show me how to use Calendar
on my case ? or how to solve this ?
public class OrderActivity extends AppCompatActivity {
Button dateButton1, dateButton2;
Calendar calender = Calendar.getInstance();
Date today = new Date();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_order);
dateButton1 = (Button)findViewById(R.id.button5);
dateButton2 = (Button)findViewById(R.id.button6);
int amount = 1; // amount of days you want to add to the current date
SimpleDateFormat formattedDate = new SimpleDateFormat("MM");
today.setTime(System.currentTimeMillis()); //set to current date
dateButton1.setText(formattedDate.format(today));
//this code below cause app stoped when this activity start
calender.add(Calendar.DATE, amount);
String newDate = (String)(formattedDate.format(calender.getTime()));
dateButton2.setText(formattedDate.format(newDate));
}}
This was my last build, how can I apply the next date on dateButton2, the date after that on dateButton3 and so on?
so far when enter this activity app closed and this is on the logcat
> java.lang.IllegalArgumentException: Cannot format given Object as a Date
at java.text.DateFormat.format(DateFormat.java:306)
at java.text.Format.format(Format.java:157)
PS: sorry for bad English