getBoundsOnScreen(android.graphics.Rect)’ on a null object reference

print

getBoundsOnScreen(android.graphics.Rect)’ on a null object reference

Set the hint on the TextInputLayout instead of the nested EditText. It wont crash.

<android.support.design.widget.TextInputLayout
                    android:id="@+id/til1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:hint="Phone Number">
                    <EditText
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:id="@+id/login_phone"
                        android:inputType="number"
                        android:singleLine="true" />
                </android.support.design.widget.TextInputLayout>

https://medium.com/@markchristopherng/a-new-year-a-new-os-upgrade-to-oreo-2f91783e159f

Testing

After doing the upgrade, everything seemed fine on the surface until we started regression testing the app. We found that the app would crash when the EditText fields got focus. One of my work colleagues, Luke Simpson found a fix to this which he posted on StackOverflow. This requires updating the v26/theme.xml file to exclude autofill.

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">

<style name="AP.Widget.EditText" parent="Widget.AppCompat.EditText">
    <item name="android:textAppearance">
      @style/AP.TextAppearance.AppCompat.Input.Value
    </item>
    <item name="android:textColor">@color/AP_P_Grey</item>
    <item name="android:importantForAutofill">
     noExcludeDescendants
    </item>
</style>
    
</resources>

This fixed most but not all of our autofill crashes, we found that if we long clicked in some fields it would still crash the app. This was caused by having a hint label on our EditTexts with TexInputLayouts in our XML layouts. Once we moved the hint to the TextInputLayout in all our layouts we could finally say goodbye to the autofill crash.

<android.support.design.widget.TextInputLayout
 android:id="@+id/textEmailLayout"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"                                  android:hint="@string/email_address"
 android:labelFor="@+id/textEmail">
   <EditText android:id="@+id/textEmail"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:cursorVisible="true"
             android:inputType="textEmailAddress"
             android:nextFocusDown="@+id/textPassword"
             android:nextFocusRight="@+id/textPassword"
             android:maxLines="1" />
</android.support.design.widget.TextInputLayout>

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.