question-mark
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.

[MaterialCalendarGridView] NullPointerException in onDraw

See original GitHub issue

Description: MaterialDatePicker crashes when using setSelection and MaterialCalendar as materialCalendarFullscreenTheme. The crash happens when swiping to the left after the dialog shows up.

Source code:

<item name="materialCalendarFullscreenTheme">@style/ThemeOverlay.MaterialComponents.MaterialCalendar</item>
MaterialDatePicker.Builder.dateRangePicker()
    .setSelection(new Pair(1485129600000l, 1590537600000l))
    .build()
    .show(getSupportFragmentManager(), "...");

Expected behavior: no crash

Android API version: 29

Material Library version: 1.2.0-alpha06

Device: Device on which the bug was encountered here Galaxy A10 Pixel 2 P10 lite OnePlus 7 Pro

 java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getRight()' on a null object reference
        at com.google.android.material.datepicker.MaterialCalendarGridView.onDraw(MaterialCalendarGridView.java:158)
        at android.view.View.draw(View.java:21609)
        at android.widget.AbsListView.draw(AbsListView.java:4514)
        at android.view.View.updateDisplayListIfDirty(View.java:20471)
        at android.view.View.draw(View.java:21336)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4413)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4174)
        at android.view.View.updateDisplayListIfDirty(View.java:20462)
        at android.view.View.draw(View.java:21336)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4413)
        at androidx.recyclerview.widget.RecyclerView.drawChild(RecyclerView.java:5030)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4174)
        at android.view.View.draw(View.java:21612)
        at androidx.recyclerview.widget.RecyclerView.draw(RecyclerView.java:4429)
        at android.view.View.updateDisplayListIfDirty(View.java:20471)
        at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4397)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4370)
        at android.view.View.updateDisplayListIfDirty(View.java:20431)
        at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4397)
        at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4370)
        at android.view.View.updateDisplayListIfDirty(View.java:20431)
        at android.view.View.draw(View.java:21336)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4413)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4174)
        at android.view.View.updateDisplayListIfDirty(View.java:20462)
        at android.view.View.draw(View.java:21336)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4413)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4174)
        at android.view.View.updateDisplayListIfDirty(View.java:20462)
        at android.view.View.draw(View.java:21336)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4413)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4174)
        at android.view.View.updateDisplayListIfDirty(View.java:20462)
        at android.view.View.draw(View.java:21336)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4413)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4174)
        at android.view.View.updateDisplayListIfDirty(View.java:20462)
        at android.view.View.draw(View.java:21336)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4413)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4174)
        at android.view.View.updateDisplayListIfDirty(View.java:20462)
        at android.view.View.draw(View.java:21336)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4413)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4174)
        at android.view.View.updateDisplayListIfDirty(View.java:20462)
        at android.view.View.draw(View.java:21336)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4413)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4174)
        at android.view.View.draw(View.java:21612)
        at com.android.internal.policy.DecorView.draw(DecorView.java:815)
        at android.view.View.updateDisplayListIfDirty(View.java:20471)
        at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:580)
        at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:586)
        at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:659)
        at android.view.ViewRootImpl.draw(ViewRootImpl.java:3876)
        at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:3676)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2998)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1935)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8023)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1163)
        at android.view.Choreographer.doCallbacks(Choreographer.java:986)
        at android.view.Choreographer.doFrame(Choreographer.java:902)```

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
SashaCubecommented, Mar 30, 2021

I’m receiving similar crashes, using version “1.3.0”

I don’t have steps to reproduce it, but they occurred on different devices (HUAWEI, Xiaomi, Samsung, OnePlus) with different android versions (10, 9, 8.1, 8.0). Maybe there is a trick with language, most users are using ‘fr’.

source:

private fun showDatePicker(from: DateTime, to: DateTime, onSubmit: (DateTime, DateTime) -> Unit) {
        val datePicker = MaterialDatePicker.Builder.dateRangePicker()
        datePicker.setSelection(Pair(from.millis, to.millis))
        val dialog = datePicker.build()
        dialog.addOnPositiveButtonClickListener {
            onSubmit(DateTime(it.first), DateTime(it.second))
        }
        dialog.show(parentFragmentManager, dialog.javaClass.simpleName)
    }

stack trace:

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.View.getLeft()' on a null object reference
       at com.google.android.material.datepicker.MaterialCalendarGridView.horizontalMidPoint(MaterialCalendarGridView.java)
       at com.google.android.material.datepicker.MaterialCalendarGridView.onDraw(MaterialCalendarGridView.java:221)
       at android.view.View.draw(View.java:23187)
       at android.widget.AbsListView.draw(AbsListView.java:7190)
       at android.view.View.updateDisplayListIfDirty(View.java:22062)
       at android.view.View.draw(View.java:22917)
       at android.view.ViewGroup.drawChild(ViewGroup.java:5230)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4987)
       at android.view.View.updateDisplayListIfDirty(View.java:22048)
       at android.view.View.draw(View.java:22917)
       at android.view.ViewGroup.drawChild(ViewGroup.java:5230)
       at androidx.recyclerview.widget.RecyclerView.drawChild(RecyclerView.java)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4987)
       at android.view.View.draw(View.java:23190)
       at androidx.recyclerview.widget.RecyclerView.draw(RecyclerView.java)
       at android.view.View.updateDisplayListIfDirty(View.java:22062)
       at android.view.View.draw(View.java:22917)
       at android.view.ViewGroup.drawChild(ViewGroup.java:5230)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4987)
       at android.view.View.updateDisplayListIfDirty(View.java:22048)
       at android.view.View.draw(View.java:22917)
       at android.view.ViewGroup.drawChild(ViewGroup.java:5230)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4987)
       at android.view.View.updateDisplayListIfDirty(View.java:22048)
       at android.view.View.draw(View.java:22917)
       at android.view.ViewGroup.drawChild(ViewGroup.java:5230)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4987)
       at android.view.View.updateDisplayListIfDirty(View.java:22048)
       at android.view.View.draw(View.java:22917)
       at android.view.ViewGroup.drawChild(ViewGroup.java:5230)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4987)
       at android.view.View.updateDisplayListIfDirty(View.java:22048)
       at android.view.View.draw(View.java:22917)
       at android.view.ViewGroup.drawChild(ViewGroup.java:5230)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4987)
       at android.view.View.updateDisplayListIfDirty(View.java:22048)
       at android.view.View.draw(View.java:22917)
       at android.view.ViewGroup.drawChild(ViewGroup.java:5230)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4987)
       at android.view.View.updateDisplayListIfDirty(View.java:22048)
       at android.view.View.draw(View.java:22917)
       at android.view.ViewGroup.drawChild(ViewGroup.java:5230)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4987)
       at android.view.View.updateDisplayListIfDirty(View.java:22048)
       at android.view.View.draw(View.java:22917)
       at android.view.ViewGroup.drawChild(ViewGroup.java:5230)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4987)
       at android.view.View.updateDisplayListIfDirty(View.java:22048)
       at android.view.View.draw(View.java:22917)
       at android.view.ViewGroup.drawChild(ViewGroup.java:5230)
       at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4987)
       at android.view.View.draw(View.java:23190)
       at com.android.internal.policy.DecorView.draw(DecorView.java:1154)
       at android.view.View.updateDisplayListIfDirty(View.java:22062)
       at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:588)
       at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:594)
       at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:667)
       at android.view.ViewRootImpl.draw(ViewRootImpl.java:4296)
       at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:4080)
       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3348)
       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2225)
1reaction
ph3mmycommented, Jun 1, 2020

I just experienced this on the android Emulator with API level 29 as well

Read more comments on GitHub >

github_iconTop Results From Across the Web

NullPointerException when creating a custom View with ...
When implementing a view, implement onDraw(android.graphics.Canvas) instead of overriding this method. If you do need to override this method, ...
Read more >
Static Analysis - Cuckoo Sandbox
Allows the app to view information about network connections such as which networks exist and are connected. android.permission.REQUEST_INSTALL_PACKAGES ...
Read more >
NullPointerException - Android Developers
NullPointerException objects may be constructed by the virtual machine as if stack trace was ... Constructs a NullPointerException with no detail message.
Read more >
Fix "java.lang.NullPointerException" in Android Studio
It is a run-time exception that arises when an application or a program tries to access the object reference(accessing methods) which has a...
Read more >
java.lang.NullPointerException @ SurfaceControl.java line 89 ...
NullPointerException : Attempt to invoke direct method 'void android.view.SurfaceControl. ... onDraw(ActivityThread.java:4175) at android.view.
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found