19

After moving to android-x I noticed that there are plenty of logs saying:

"E/itterforandroi: Invalid ID 0x00000000."

I manage to circle down to the point where I'm creating a new RecyclerView ViewHolder and inflating a layout that contains a Chip. Every other field does not show such an error, only Chip.

In the xml it's looking like so:

<com.google.android.material.chip.Chip
    android:id="@+id/someChip"
    style="@style/Widget.MaterialComponents.Chip.Action"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="left|center"
    android:layout_marginRight="10dp"
    android:layout_marginBottom="10dp"
    app:chipIcon="@drawable/ic_account_circle_black_24dp"
    app:chipIconEnabled="true" />

I cannot find what is really missing in this definition that causes the error. Any hint?

Fiszu
  • 268
  • 1
  • 3
  • 7
  • For **AndroidX** custom implementation https://github.com/karanatwal/MaterialChipsInput – karanatwal.github.io Apr 12 '19 at 11:45
  • I had this same problem but it appears to have been fixed in material components 1.1.0 (still in alpha) – Alex Baker Apr 23 '19 at 17:17
  • It happens because of font family resource. Even though font family is specified in a chip, `TextAppearance.fontFamilyResourceId` is set to zero(0), which triggers __Invalid ID 0x00000000__ on every devices. Chip implementation in metrial-1.0.0 does not seem to handle font-related information. – chmin.seo Nov 26 '19 at 05:26
  • can confirm this is a bug in material components 1.0.0, when using new version(as of now is: 1.2.0-alpha02) update version and the error will be fixed – rollcage Dec 10 '19 at 11:25
  • 1
    I can confirm that this bug still exists in material:1.3.0-alpha01 and happening when the app is launched for the first time after installation and when the android kills the app and relaunch it again. – Raed Jun 30 '20 at 12:05
  • I am getting the same log. But I can't figure what occurring this problem. How did you point out that it's happening because of chip? In my case, it wasn't happening in my phone I developed 90% of the app on my phone then tested it out in a oneplus phone then it's only occurring in that phone. – Karan Malhotra Oct 16 '21 at 06:38

1 Answers1

3

I was having the same issue with chip inflation and I fixed this error by switching to a data binding layout for my chip as shown below.

I also think you should remove your "android:id" property in the xml since you are using a RecyclerView to populate chips dynamically. It should autogenerate an id for you.

<layout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    
    <data>
        <import type="android.content.Context" />
        <variable
            name="element"
            type="com.android.sarahmica.app.database.Element" />
    </data>
    
    <com.google.android.material.chip.Chip
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="16sp"
        android:clickable="true"
        android:focusable="true"
        android:text="@{element.name}"
        android:tag="@{element.id}"
        app:chipBackgroundColor="@{element.getChipColor(context)}"
        style="@style/Widget.MaterialComponents.Chip.Filter" />
</layout>

And then I inflate my chips from an a list in the fragment like so (but since you are using a RecycylerView, you'll have to adjust your adapter to use databinding accordingly)

val chipGroup = getChipGroup(type)
val inflater = LayoutInflater.from(chipGroup.context)
elementList.forEach { element ->
    val chipBinding: MyChipBinding = DataBindingUtil.inflate(inflater, R.layout.my_chip, chipGroup, true)
    chipBinding.greenActivity = activity
    binding.lifecycleOwner = this
}

I hope my solution helps you!!

Sarah Mica
  • 121
  • 1
  • 7