Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MaterialToolbar] NPE on tab switch with logo changes #2708

Closed
kvn-stgl opened this issue May 17, 2022 · 0 comments
Closed

[MaterialToolbar] NPE on tab switch with logo changes #2708

kvn-stgl opened this issue May 17, 2022 · 0 comments
Assignees
Labels

Comments

@kvn-stgl
Copy link

kvn-stgl commented May 17, 2022

Description:
I want to display the app logo in the MaterialToolbar only on the start tab. To achieve this I wrote a destinationChangedListener for the navController and used the setLogo method to set the logo null on specified tabs.
With 1.5 every works like a charm, with 1.6 I will receive an NPE.

Source code:

        navController.addOnDestinationChangedListener { _, _, arguments ->
            val showLogo = arguments?.getBoolean("showLogo", false) ?: false
            if (showLogo) {
                supportActionBar?.setLogo(R.drawable.ic_logo)
            } else {
                supportActionBar?.setLogo(null)
            }
        }

Error message:

2022-05-17 10:16:25.150 10665-10665/de.rnd.news.qa E/AndroidRuntime: FATAL EXCEPTION: main
    Process: ***, PID: 10665
    java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.Object.equals(java.lang.Object)' on a null object reference
        at com.google.android.material.internal.ToolbarUtils.getImageView(ToolbarUtils.java:98)
        at com.google.android.material.internal.ToolbarUtils.getLogoImageView(ToolbarUtils.java:88)
        at com.google.android.material.appbar.MaterialToolbar.updateLogoImageView(MaterialToolbar.java:208)
        at com.google.android.material.appbar.MaterialToolbar.onLayout(MaterialToolbar.java:135)
        at android.view.View.layout(View.java:23144)
        at android.view.ViewGroup.layout(ViewGroup.java:6412)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1829)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1673)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1582)
....

Material Library version: 1.6

@kvn-stgl kvn-stgl added the bug label May 17, 2022
@dsn5ft dsn5ft self-assigned this May 17, 2022
pekingme pushed a commit that referenced this issue May 25, 2022
Resolves #2708

PiperOrigin-RevId: 449305810
(cherry picked from commit 2ac796f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants