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 in 1.3.0

See original GitHub issue

Description: I’m receiving a similar bug to https://github.com/material-components/material-components-android/issues/1338, but using version “1.3.0”

I don’t have steps to reproduce, but It occurred on different devices with different android versions. Maybe there is a trick with language, most users are using ‘fr’.

Expected behavior: expect the app will not crash

Source code:

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)
    }

Android API versions: 29, 28, 27, 26

Material Library version: 1.3.0

Devices: Huawei P20 Xiaomi Redmi 9 Samsung Galaxy S7 Samsung Galaxy S7 edge Samsung Galaxy A41 Samsung Galaxy Note 10 Samsung Galaxy S9 OnePlus 6

Stacktrace:

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)

I going to try the latest release 1.4.0-alpha01 of the library. But I can’t reproduce this issue by myself, so the only way is to receive crash information from Firebase, it’s painful. Maybe someone faced the same issue, will be thankful for any help.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
SashaCubecommented, Jun 11, 2021

I’m getting the same crash on Lenovo TB-8504X with Android 8.1.0. Many of our users getting this crash, all with the same model device and Android version. Tried everything, cannot reproduce even when using exactly the same device model and Android version. Using version 1.3.0 of the Material Components library with the bridge app theme Theme.MaterialComponents.Light.NoActionBar.Bridge.

We had the same problem on production recently. I have managed to reproduce it by using Foldable emulator. (You will find it in awd manager ). The only way to fix it was forking the project and fixing it in MaterialComponents.

I’ve used the same solution. Opened PR to this issue is based on fix which I used on prod, hope it will be rewived soon.

1reaction
mirjalalcommented, Apr 21, 2021

@vladyslavkhimich checkout this one. Additionally, I highly recommend you to read this issue 🙂 Cheers 🥳

Read more comments on GitHub >

github_iconTop Results From Across the Web

MaterialDatePicker, app crashes after selecting the end date
NullPointerException : Attempt to invoke virtual method 'int android.view. ... onDraw(MaterialCalendarGridView.java:172) at android.view.
Read more >
Fusion Middleware Environment is Failing with "java.lang ...
Fusion Middleware Environment is Failing with "java.lang.NullPointerException" When Upgraded From 12.2.1.3.0 to 12.2.1.4.0 (Doc ID 2856353.1).
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 >

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