zcustomcalendar icon indicating copy to clipboard operation
zcustomcalendar copied to clipboard

App crash on date click after navigating to other month

Open ashik991 opened this issue 4 years ago • 7 comments

I get this error, "Attempt to invoke interface method 'java.lang.Object java.util.Map.get(java.lang.Object)' on a null object reference at org.naishadhparmar.zcustomcalendar.CustomCalendar$3.onClick(CustomCalendar.java:275)", when I navigate to the next month and click on a date.

ashik991 avatar Jan 06 '21 05:01 ashik991

Same here. I encounter the same issue: java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.Map.get(java.lang.Object)' on a null object reference at org.naishadhparmar.zcustomcalendar.CustomCalendar$3.onClick(CustomCalendar.java:275)

MagdalineMbugua avatar Mar 04 '21 10:03 MagdalineMbugua

Any solution for this?

shahina-almarwan avatar Mar 18 '22 20:03 shahina-almarwan

OnNavigationButtonClickedListener use whichbutton you click after that implement desired view that you want

subhsis avatar Jun 01 '22 04:06 subhsis

OnNavigationButtonClickedListener use whichbutton you click after that implement desired view that you want

It would be very nice of you if you share this specific code.

sohail756 avatar Aug 21 '22 21:08 sohail756

@Override public Map<Integer, Object>[] onNavigationButtonClicked(int whichButton, Calendar newMonth) { Map<Integer, Object>[] arr = new Map[2];

    if (whichButton==CustomCalendar.NEXT){
        //  view you want
    }if (whichButton==CustomCalendar.PREVIOUS){
              //  view you want
    }
    return arr;
}

--> call calendar instance to get the current month and implement on view as per your requirement.

subhsis avatar Sep 07 '22 16:09 subhsis

I get this error, "Attempt to invoke interface method 'java.lang.Object java.util.Map.get(java.lang.Object)' on a null object reference at org.naishadhparmar.zcustomcalendar.CustomCalendar$3.onClick(CustomCalendar.java:275)", when I navigate to the next month and click on a date.

I encountered the same issue because i was calling this listener directly without using hashmap or simply i can say without defining properties and setting these to hashmap. I defined one property ("default") ,then this listener worked.

shamali1013 avatar Sep 10 '22 16:09 shamali1013

override fun onNavigationButtonClicked( whichButton: Int, newMonth: Calendar? ): Array<MutableMap<Int, Any>?> { val arr = arrayOfNulls<MutableMap<Int, Any>>(2)

    val currentMonth: Month = LocalDate.now().month
    val currentYear: Int = LocalDate.now().year
    if (newMonth != null) {
        if (newMonth.get(Calendar.MONTH)+1>currentMonth.value){
            customeCalander.setNavigationButtonEnabled(CustomCalendar.PREVIOUS,true)
        }else{

            if (newMonth.get(Calendar.YEAR)==currentYear)
            customeCalander.setNavigationButtonEnabled(CustomCalendar.PREVIOUS,false)
            else
                customeCalander.setNavigationButtonEnabled(CustomCalendar.PREVIOUS,true)
        }



    }


    when (newMonth?.get(Calendar.MONTH)) {
        Calendar.JANUARY -> {
            arr[0] = HashMap<Int, Any>().apply {

            }
            arr[1] = null // Optional: This is the map linking a date to its tag.
        }
        Calendar.FEBRUARY -> {
            arr[0] = HashMap<Int, Any>().apply {

            }
            arr[1] = null // Optional: This is the map linking a date to its tag.
        }
        Calendar.MARCH -> {
            arr[0] = HashMap<Int, Any>().apply {

            }
        }
        Calendar.APRIL -> {
            arr[0] = HashMap<Int, Any>().apply {

            }
            arr[1] = null // Optional: This is the map linking a date to its tag.
        }
        Calendar.JULY -> {
            arr[0] = HashMap<Int, Any>().apply {

            }
            arr[1] = null // Optional: This is the map linking a date to its tag.
        }
        Calendar.AUGUST -> {
            arr[0] = HashMap<Int, Any>().apply {

            }
            arr[1] = null // Optional: This is the map linking a date to its tag.
        }
        Calendar.JUNE -> {
            arr[0] = HashMap<Int, Any>().apply {

            }
        }
        Calendar.MAY -> {
            arr[0] = HashMap<Int, Any>().apply {

            }
        }
        Calendar.SEPTEMBER -> {
            arr[0] = HashMap<Int, Any>().apply {

            }
        }
        Calendar.OCTOBER -> {
            arr[0] = HashMap<Int, Any>().apply {

            }
        }
        Calendar.NOVEMBER -> {
            arr[0] = HashMap<Int, Any>().apply {

            }
        }
        Calendar.DECEMBER -> {
            arr[0] = HashMap<Int, Any>().apply {

            }
        }
    }



    return arr


}

try this code...

Dyenal avatar May 08 '23 15:05 Dyenal