Android Constant and Resource Type Mismatches Lint


If you are getting this kind of Lint error messages in your Android Logcat console then the reason can be one of the following,

1. Due to invalid Resource Identifier specified.

You might have provided a wrong type of resource identifier in the Java code,

Example, If you are trying to access a resources file you must use something like Resources.getString(int id), you may be passing R.string.something instead of R.drawable.something. Just check for such kind of access codes in your Java file and rectify them.

2. Passing the wrong constant to a method.

You might be passing a wrong constant to a method which might be expecting something else

For example, when calling View#setLayoutDirection, the parameter must be android.view.View.LAYOUT_DIRECTION_LTR or android.view.View.LAYOUT_DIRECTION_RTL. Let's see an example where you have a Button and you try to access this button as button = findViewById(1);, you will get the error message as,

Expected Resource type id: Supplying the wrong type of resource identifier.

For example, when calling Resources.getString(int id), you should be passing R.string.something, not R.drawable.something. Passing the wrong constant to a method that expects one of a specific set of constants.

For example, when calling View#setLayoutDirection, the parameter must be android.view.View.LAYOUT_DIRECTION_LTR or android.view.View.LAYOUT_DIRECTION_RTL.