Android Edittext Exception - How to resolve IndexOutOfBounds exception


Android - IndexOutOfBounds Exception while using textAllCaps in Edittext



There can be many cases that generate IndexOutOfBounds Exception. While using ArrayList, looping, and adaptors, are all kinds of lists that generate this exception. But there is also another case that generates IndexOutOfBounds Exception, which is while using the textAllCaps property in EditText. So let's talk about that.

Generally, when the app requires to fill data in forms or any text fields in capital form, the first thing that comes to mind is textAllCaps. Why? Because it works perfectly while displaying data in TextViews. Right?

We think that it will also work perfectly with EditText. But that's where things go wrong. If we use the textAllCaps property in EditText, it starts giving exceptions while typing, and the app crashes.

The reason is simple. textAllCaps is a property of TextView, not EditText. So, it is not compatible with EditText and it generates crashes. Though it EditText is a direct sub-class of TextView, it inherits the property.

If we use android:inputType="textCapCharacters" it will convert all characters into UPPER CASE, like we want in textAllCaps. There are some other attributes for that property that you can find on the developer page.


Thanks for reading this article. Hope you would have liked it!. Please share and subscribe to my blog to support.

Pragnesh Ghoda

A forward-thinking developer offering more than 8 years of experience building, integrating, and supporting android applications for mobile and tablet devices on the Android platform. Talks about #kotlin and #android

Post a Comment

Please let us know about any concerns or query.

Previous Post Next Post

Contact Form