Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Attempt to invoke virtual method 'void android.view.View.getBoundsOnScreen(android.graphics.Rect)' on a null object reference

Problem is a known Android bug. From the Google issue tracker suggestions, setting the hint on the TextInputEditText seems to be causing the crash. Setting the hint only on the TextInputLayout fixes the crash.

This issue only happens IF the hint is set on the nested EditText inside the TextInputLayout. I resolved it by setting the hint on the TextInputLayout.

https://issuetracker.google.com/issues/62834931 Comment #28


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>

Adding this code on each Edit Text solved my problem:

android:importantForAutofill="noExcludeDescendants"