Saikrishna Rajaraman
Saikrishna Rajaraman

Reputation: 3273

Constraint layout Layout Crashing : All Children of constraint layout should have ids to use constraint set

After updating to com.android.support.constraint:constraint-layout:1.1.0

The constraint layout crashes saying:

All children of constraint layout should have ids to use constraint set

I have set ids to all views even then it's crashing.

java.lang.RuntimeException: All children of ConstraintLayout must have ids to use ConstraintSet at android.support.constraint.ConstraintSet.clone(ConstraintSet.java:687) at com.zoho.notebook.views.SettingsViewNavBar.showNoteSettingsView(SettingsViewNavBar.java:594) at com.zoho.notebook.views.SettingsViewNavBar.onClick(SettingsViewNavBar.java:303)

Upvotes: 31

Views: 20936

Answers (7)

Roman Markov
Roman Markov

Reputation: 21

In my case, the crash appeared after I used the Refactor -> Remove Unused Resources feature. This action deleted an ID from the MotionScene layout description, and the same ID was also removed from the corresponding MotionLayout.

Upvotes: 0

basileus
basileus

Reputation: 445

I had this error when I tried to add new View at onGlobalLayout() (after main Layout is finalized). All id's in Layout were correct, new dynamical View ID was set (with setId()). But fault "All Children of constraint layout should have ids to use constraint set" kept occuring.

When I moved adding View to onCreate() everything went smooth. I just needed to change logic however on how where to put new View, as position of other Views is not determined at onCreate().

Upvotes: 0

rizkidzulkarnain
rizkidzulkarnain

Reputation: 61

In my case Don't forget to add ID to all child of contraintLayout

Upvotes: 0

sayleep
sayleep

Reputation: 19

I was getting this error until I realized that I hadn't given ids to some of the child elements in the ConstraintLayout. So, make sure you do not forget to do that either.

Upvotes: 2

Onderbetaald
Onderbetaald

Reputation: 341

Don't forget to give the ConstraintLayout an id as well.

I forgot this and it crashed my code. This isn't really obvious from the error.

Upvotes: 19

LVS
LVS

Reputation: 86

I just figure out how to fix this problem. Notice that is you must declare all view on ConstrainLayout have set ids, check example below:

In case 1 it's working success.

<android.support.constraint.ConstraintLayout 
    android:id="@+id/viewGroup"
    ...>
    <ImageView
        android:id="@+id/imgId"
        ... />
    <TextView
        android:id="@+id/txtId"
        ... />

In case 2 below not working.

<android.support.constraint.ConstraintLayout 
        android:id="@+id/viewGroup"
        ...>
        <ImageView
            android:id="@+id/imgId"
            ... />
        <TextView
          // do not set ids
            ... />

I hope this it will helpful for you.

Upvotes: 6

hushed_voice
hushed_voice

Reputation: 3608

I had the same bug in my code. I had ids for all the views in xml, but I was manually adding a view to the constraint layout(a Tooltip view) with

constraintParent.addView(childView)

and while the dynamically added view is still on the parent if the constraint layout is redrawn (app goes to bg and resumed) this exception was getting triggered.

I fixed it by generating a view id for the dynamic view like this

CustomViewChildView childView = new CustomViewChildView()
childView.setId(View.generateViewId()); 

and then adding it to the constraint layout.

Upvotes: 53

Related Questions