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.

[Tab Items] Tab Items does not work with View Binding, throws NPE

See original GitHub issue

Description: Filing this in response to ja…@google.com comment on https://issuetracker.google.com/issues/145687658

a…@tandu.it

I have a view which contains some TabItem with an ID. When I try to generate my binding with .inflate() the app throws an NPE on those views. This happens on both Activity and Fragment.

ja…@google.com :

My working theory is material library is doing something horrific like intercepting TabLayout.addView and not actually putting the views into the hierarchy synchronously.

ja…@google.com :

Indeed, that is the problem.

2019-12-09 15:57:32.859 6425-6425/? I/System.out: FrameLayout ID:16908290 2019-12-09 15:57:32.859 6425-6425/? I/System.out: LinearLayout ID:2131230917 2019-12-09 15:57:32.859 6425-6425/? I/System.out: TabLayout ID:-1 2019-12-09 15:57:32.859 6425-6425/? I/System.out: SlidingTabIndicator ID:-1 2019-12-09 15:57:32.859 6425-6425/? I/System.out: TabView ID:-1 2019-12-09 15:57:32.859 6425-6425/? I/System.out: ImageView ID:-1 2019-12-09 15:57:32.859 6425-6425/? I/System.out: TextView ID:-1 2019-12-09 15:57:32.859 6425-6425/? I/System.out: TabView ID:-1 2019-12-09 15:57:32.859 6425-6425/? I/System.out: ImageView ID:-1 2019-12-09 15:57:32.859 6425-6425/? I/System.out: TextView ID:-1

Please file a bug on the Google Material library that it should consider retaining the IDs if one was supplied.

I’ll repurpose this issue for honoring our tools:viewBindingIgnore attribute on arbitrary XML nodes to at least work around the issue.

Expected behavior: Tab Items working with View Binding without throwing NPEs

Source code: Required source files could be found at https://issuetracker.google.com/issues/145687658

Material Library version:

Android Material dependency: com.google.android.material:material:1.1.0-beta01

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:13
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

18reactions
Dreft12commented, Feb 11, 2021

Still happening, I found a workaround, try this:

Go to your XML and search the ID that is generating the issue and delete its android:id

Use the TabLayout API in your class to access the TabItems.

For example, this is my XML:

<com.google.android.material.tabs.TabItem android:id=“@+id/tbItem” <!-- Delete this line -> android:layout_width=“wrap_content” android:layout_height=“wrap_content” android:layout_gravity=“bottom” android:backgroundTintMode=“screen” android:text=“@string/mosaic” />

Go to your class: And use this:

val tabView: TabLayout = binding.tbType //This is my tab layout tabView.getTabAt(0)!!.text = “Example 1”

4reactions
dzzchaocommented, Jan 20, 2021

When will this bug be fixed? Still happening with 1.3.0-rc01

Read more comments on GitHub >

github_iconTop Results From Across the Web

Developers - [Tab Items] Tab Items does not work with View Binding ...
I have a view which contains some TabItem with an ID. When I try to generate my binding with .inflate() the app throws...
Read more >
java.lang.NullPointerException: Missing required view with ID
The solution is to ensure the layout you are binding to the view is the same layout as the ViewBinding. For example, makesure:...
Read more >
Support viewBindingIgnore on arbitrary XML nodes [145687658]
I have a view which contains some TabItem with an ID. When I try to generate my binding with .inflate() the app throws...
Read more >
Getting NullPointerException, the getCurrentInstance() in the ...
I am trying to implement dynamic tabs using ADF Dynamic UI Shell. After clicking on a link, a dynamic tab opens up which...
Read more >
Release Notes | GXT 4.x - Sencha Documentation
GXT 4.0.3 the fields height setting works, so that means a parent may stretch ... [EXTGWT-4847] - Window does not focus items correctly...
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