Android Runtime Error: Invalid ID 0x00000001 happening during Chip inflation

3

I have a screen that populates a bunch of Chips into a ChipGroup from the database, and they are all populated appropriately but I keep seeing a bunch of these errors when I navigate to the screen.

E/sarahmica.myapp: Invalid ID 0x00000000.
E/sarahmica.myapp: Invalid ID 0x00000001.
E/sarahmica.myapp: Invalid ID 0x00000005.
E/sarahmica.myapp: Invalid ID 0x0000000b.
E/sarahmica.myapp: Invalid ID 0x00000002.

I commented a bunch of things out line by line to isolate the error (since there is no useful information in that message) and I've determined this chunk of code that dynamically creates Chip views to be the source. I don't know why it is having an issue inflating chips.

Initially I wasn't setting the id so I added it here in an attempt to fix the issue, but it did nothing (and View.generateViewId() was the Android recommended way for how to programatically set id)

val chipGroup = getChipGroup(type) 
val inflater = LayoutInflater.from(chipGroup.context)

// for each activity item in the list, create a chip
val children: List<Chip> = activityList.map { activity ->
    val chip = inflater.inflate(R.layout.my_activity_chip, chipGroup, false) as Chip
    chip.id = View.generateViewId()
    chip.text = activity.activityName
    chip.tag = activity.activityId
    chip.chipBackgroundColor = getChipColor(type)
    chip
}

chipGroup.removeAllViews()

for (chip in children) {
    chipGroup.addView(chip)
}

Here is the layout for the chip element that I am inflating ("my_activity_chip.xml")

<?xml version="1.0" encoding="utf-8"?>

<com.google.android.material.chip.Chip
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="16sp"
    android:clickable="true"
    android:focusable="true"
    style="@style/Widget.MaterialComponents.Chip.Filter"/>

As I mentioned, everything is rendering fine so this is not a big deal, but I want to make sure this bug is not actually an issue and would like to clean up my logs!

I saw someone else had a similar issue to mine, but there were no answers so if anyone has any ideas on what could be causing this, thanks for any help!

android
android-chips
asked on Stack Overflow Aug 21, 2020 by Sarah Mica

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0