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.






Recent Posts:
Hello there!,

You are using AdBlocker!

I am an independent developer trying to help fellow developers and students to resolve issues faced on a day-to-day basis, we 'Code to Care' . There is a lot of expenses involved in hosting and managing a website that's the reason we have ads.

A humble request to you to disable adBlocker on Code2care.org and support us pay our bills.

Thanks,
Cod2ecare - Line's of code for change.

To see contents reload page after unblocking
Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.