Android Data Binding Error : non-static variable R cannot be referenced from a static context

Viewed 106

This is not a Question, I'm sharing an Experience.

If you ever faced the following error while compiling an android project which uses Data Binding

error: non-static variable R cannot be referenced from a static context
    View root = inflater.inflate(R.layout.YOUR_LAYOUT_FILE, parent, false)

Please make sure no element (View / ViewGroup) in your XML file has the id "R"

android:id="@+id/R"

Because the auto-generated binding class will create an attribute named R and will confuse with your project ressources R

as dumb as it may sound, a little lack of concentration may produce an error that is so confusing, frustrating, hard to detect and most importantly time-wasting

0 Answers
Related