I tried to create a simple activity with a button and a textview that showing the date. The button should show the HijriDatePicker dialog when clicked. I tried to make it using ummalqura-calendar and by the dialog, i tried use the HijriDatePicker to create the dialog.
However, after many attempts, it doesn't work. Sometimes the activity will stop when I click the button, and sometimes it just crash. I tried already for many fail attempts.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.myapplication, PID: 13658
com.github.msarhan.ummalqura.calendar.DateTimeException: Invalid Hijrah day of month: 31
at com.github.msarhan.ummalqura.calendar.HijrahChronology.getEpochDay(HijrahChronology.java:255)
at com.github.msarhan.ummalqura.calendar.HijrahChronology.toGregorian(HijrahChronology.java:697)
at com.github.msarhan.ummalqura.calendar.UmmalquraCalendar.set(UmmalquraCalendar.java:259)
at net.alhazmy13.hijridatepicker.date.hijri.HijriDatePickerDialog.getEndDate(HijriDatePickerDialog.java:1028)
at net.alhazmy13.hijridatepicker.date.hijri.MonthAdapter.getCount(MonthAdapter.java:146)
at android.widget.ListView.setAdapter(ListView.java:493)
at net.alhazmy13.hijridatepicker.date.hijri.DayPickerView.refreshAdapter(DayPickerView.java:142)
at net.alhazmy13.hijridatepicker.date.hijri.DayPickerView.setController(DayPickerView.java:114)
at net.alhazmy13.hijridatepicker.date.hijri.DayPickerView.<init>(DayPickerView.java:105)
at net.alhazmy13.hijridatepicker.date.hijri.SimpleDayPickerView.<init>(SimpleDayPickerView.java:32)
at net.alhazmy13.hijridatepicker.date.hijri.HijriDatePickerDialog.onCreateView(HijriDatePickerDialog.java:340)
at androidx.fragment.app.Fragment.performCreateView(Fragment.java:2600)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:881)
at androidx.fragment.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManagerImpl.java:1238)
at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:1303)
at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:439)
at androidx.fragment.app.FragmentManagerImpl.executeOps(FragmentManagerImpl.java:2079)
at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1869)
at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1824)
at androidx.fragment.app.FragmentManagerImpl.execPendingActions(FragmentManagerImpl.java:1727)
at androidx.fragment.app.FragmentManagerImpl$2.run(FragmentManagerImpl.java:150)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6119)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
and my main activity java
public class MainActivity extends AppCompatActivity implements HijriDatePickerDialog.OnDateSetListener{
TextView tvDate;
TextView etDate;
HijriDatePickerDialog.OnDateSetListener setListener;
public MainActivity() {
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvDate = findViewById(R.id.tv_date);
etDate = findViewById(R.id.et_date);
tvDate.setOnClickListener(v -> {
UmmalquraCalendar now = new UmmalquraCalendar();
HijriDatePickerDialog dpd = HijriDatePickerDialog.newInstance(
MainActivity.this,
now.get(Calendar.YEAR),
now.get(Calendar.MONTH),
now.get(Calendar.DAY_OF_MONTH)
);
dpd.setMinDate(new UmmalquraCalendar(1440,0,1));
dpd.show(getSupportFragmentManager(), "Datepickerdialog");
});
}
@Override
public void onResume() {
super.onResume();
assert getFragmentManager() != null;
HijriDatePickerDialog dpd = (HijriDatePickerDialog) getSupportFragmentManager().findFragmentByTag("Datepickerdialog");
if (dpd != null) dpd.setOnDateSetListener(this);
}
@Override
public void onDateSet(HijriDatePickerDialog view, int year, int monthOfYear, int dayOfMonth) {
String date = "You picked the following date: " + dayOfMonth + "/" + (++monthOfYear) + "/" + year;
System.out.println(date);
etDate.setText(date);
}
}
This problem seems to be a known bug in the msarhan-library. There was also a meanwhile closed issue on its related website. It indicates that a fix has been applied in the newest version.
So I suggest you to update your marhan library to version v2.0.2 which might solve your problem.
When looking at the date-picker-library you use we can see that it still uses the version v2.0.1. Either you wait until the author of the date-picker-library fixes the dependency or you build your own version of the date-picker-library.