Android Layout findViewById Returns Null

Every once in a while you run across a coding issue that has occurred in the past but you can’t remember the resolution. Tonight is one of those times and the issue was an Android Layout one.

I had a layout xml file with the following id on a TextView:


In the OnCreate() method I set the content view:


And then went to get the TextView as such:

TextView foo = (TextView) this.findViewById(;

The problem is, foo is always null.

The issue here is that you must use the correct schema for the id node, which I’m guessing is compiling correctly due to some past version compatibility “feature” in the Android code. Simply making the change to use android:id as shown below, made the null an issue of my past (again) and now I can move on to using the TextView any way I like.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.