Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.


See original GitHub issue

Hi, thank’s for great lib. However, I faced the issue: crash when first open a fragment with calendar view. It happened once, and I think the problem is in using unsafe (!!) call.

        at com.kizitonwose.calendarview.ui.MonthViewHolder.bindMonth(MonthViewHolder.kt:39)
        at com.kizitonwose.calendarview.ui.CalendarAdapter.onBindViewHolder(CalendarAdapter.kt:144)
        at com.kizitonwose.calendarview.ui.CalendarAdapter.onBindViewHolder(CalendarAdapter.kt:27)
        at androidx.recyclerview.widget.RecyclerView$Adapter.onBindViewHolder(
        at com.kizitonwose.calendarview.ui.CalendarAdapter.onBindViewHolder(CalendarAdapter.kt:135)
        at com.kizitonwose.calendarview.ui.CalendarAdapter.onBindViewHolder(CalendarAdapter.kt:27)
        at androidx.recyclerview.widget.RecyclerView$Adapter.bindViewHolder(
        at androidx.recyclerview.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(
        at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(
        at androidx.recyclerview.widget.LinearLayoutManager$
        at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(
        at androidx.recyclerview.widget.LinearLayoutManager.fill(
        at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(
        at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(
        at androidx.recyclerview.widget.RecyclerView.dispatchLayout(
        at androidx.recyclerview.widget.RecyclerView.onLayout(
        at android.view.View.layout(
        at android.view.ViewGroup.layout(
        at androidx.constraintlayout.widget.ConstraintLayout.onLayout(
        at android.view.View.layout(
        at android.view.ViewGroup.layout(
        at android.widget.FrameLayout.layoutChildren(
        at android.widget.FrameLayout.onLayout(
        at android.view.View.layout(
        at android.view.ViewGroup.layout(
        at androidx.appcompat.widget.ActionBarOverlayLayout.onLayout(

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

EgorThe1stcommented, Aug 13, 2019

Here is the initialization:

 class DateSelectFragment : BaseFragment(), DateSelectView {

    companion object {
        fun newInstance(): DateSelectFragment = DateSelectFragment()

    private val today

    private val dayBinder = getDayBinder()

    lateinit var presenter: DateSelectPresenter

    override fun getLayoutRes() = R.layout.fragment_date_select

    override fun initUI() {

        Handler().post { initCalendarView() }

    private fun initCalendarView() {
        date_select_calendar_view.dayBinder = dayBinder

        date_select_calendar_view.monthFooterBinder = object : MonthHeaderFooterBinder<MonthFooterContainer> {
            override fun create(view: View) = MonthFooterContainer(view)

            override fun bind(container: MonthFooterContainer, month: CalendarMonth) {

        date_select_calendar_view.monthHeaderBinder = object : MonthHeaderFooterBinder<MonthHeaderContainer> {

            override fun create(view: View) = MonthHeaderContainer(view)

            override fun bind(container: MonthHeaderContainer, month: CalendarMonth) {
                container.monthTitle.text = month.yearMonth.format(DateTimeFormatter.ofPattern("MMM yyyy"))
        val currentMonth =
        val lastMonth = currentMonth.plusMonths(12)
        val firstDayOfWeek = WeekFields.of(Locale.getDefault()).firstDayOfWeek

        date_select_calendar_view.setup(currentMonth, lastMonth, firstDayOfWeek)

    class DayViewContainer(view: View) : ViewContainer(view) {
        val textView = view.calendar_day_text

    class MonthHeaderContainer(view: View) : ViewContainer(view) {
        val monthTitle = view.calendar_month_title

    class MonthFooterContainer(view: View) : ViewContainer(view)

    private fun getDayBinder(): DayBinder<DayViewContainer> {

        return object : DayBinder<DayViewContainer> {

            // Called only when a new container is needed.
            override fun create(view: View) = DayViewContainer(view)

            // Called every time we need to reuse a container.
            override fun bind(container: DayViewContainer, day: CalendarDay) {
                val dayText = container.textView

                fun setStandartDayColor() {
                    dayText.textColor = ContextCompat.getColor(requireContext(), R.color.blue_primary)

                fun setInactiveDayColor() {
                    dayText.textColor = ContextCompat.getColor(requireContext(), R.color.calendar_inactive_date)

                fun setFullSelectedDayView() {
                    dayText.textColor = ContextCompat.getColor(requireContext(), R.color.white)
                    dayText.background = resources.getDrawable(R.drawable.bg_calendar_selected_day_full, null)

                fun clearTextBackground() {
                    dayText.background = null

                fun setInitialState() {
                    dayText.text = null


                if (day.owner == DayOwner.THIS_MONTH) {
                    dayText.text =

                    if ( setInactiveDayColor()

                    if (! && ! {



Is it correct?

EgorThe1stcommented, Aug 14, 2019

Is the issue fixed for you? Can I close this now?

Yes, I guess

Read more comments on GitHub >

github_iconTop Results From Across the Web

Kotlin - why do I get a KotlinNullPointerException
Starting from Kotlin 1.4, the exception will be NullPointerException instead (a different type), see here. So if any code catches explicitly ...
Read more >
KotlinNullPointerException - Kotlin Programming Language
Returns an array of stack trace elements representing the stack trace pertaining to this throwable. val Throwable.stackTrace: Array<StackTraceElement> ...
Read more >
build failed with kotlin.KotlinNullPointerException
Solved: I get this issue after an update followed by a rollback against the Gradle version. Background: Bamboo builds with Docker run tasks....
Read more >
java.lang.NullPointerException is thrown instead of kotlin ...
NullPointerException is thrown instead of kotlin.KotlinNullPointerException in not-null assertions. Duplicates 1. Duplicates 1 issue (0 unresolved).
Read more >
internal error (Caused by: kotlin.KotlinNullPointerException) #23
I got kotlin.KotlinNullPointerException when try to debug. The error seems to be caused by JDILauncher.createLaunchArgs The full error log: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found