попытка вызвать виртуальный метод 'android .widget.EditText android .support.design.widget.TextInputLayout.getEditText ()' для ссылки на пустой объект - PullRequest
1 голос
/ 06 января 2020

Получаю ошибку в android studio: "java .lang.NullPointerException: попытка вызвать виртуальный метод" android .widget.EditText android .support.design.widget.TextInputLayout.getEditText () ' "для пустой ссылки на объект". Пожалуйста, помогите мне решить эту проблему. Я уже проверил все решения на стеке потока, но не смог решить проблему.

`

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/White">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/sign_up_layout"
        android:padding="20dp"
        android:background="@drawable/sign_up_layout_bg">
        <ImageView

            android:id="@+id/logo"
            android:layout_width="100dp"
            android:layout_height="100dp"
            android:layout_marginTop="20dp"
            android:contentDescription="@string/image_view_des"
            android:layout_centerInParent="true"
            android:layout_alignParentTop="true"
            android:src="@drawable/logo" />

        <TextView
            android:id="@+id/text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/sign_up"
            android:textColor="@color/White"
            android:typeface="serif"
            android:layout_below="@+id/logo"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="40dp"
            android:textSize="24sp"/>
    </RelativeLayout>
    <android.support.v7.widget.CardView
        android:layout_centerHorizontal="true"
        android:layout_width="350dp"
        android:id="@+id/cardView"
        android:layout_marginTop="200dp"
        android:layout_height="270dp">
        <RelativeLayout
            android:padding="10dp"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:id="@+id/full_name_input"
                android:hint="@string/username_hint"
                android:layout_height="wrap_content">
                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:inputType="text"
                    android:textColor="@color/Dark"
                    android:drawableRight="@drawable/ic_user_blue_24dp"
                    android:drawableEnd="@drawable/ic_user_blue_24dp"
                    android:id="@+id/UserEditText"/>
            </android.support.design.widget.TextInputLayout>
            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_below="@id/full_name_input"
                android:id="@+id/pass_input"
                android:hint="@string/password_hint"
                android:layout_height="wrap_content">
                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:inputType="textPassword"
                    android:textColor="@color/Dark" />
                <!--    android:id="@+id/PassEditText" -->
            </android.support.design.widget.TextInputLayout>
            <ImageButton
                android:id="@+id/pass_view"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/ic_pass_eye_blue_24dp"
                android:layout_alignBottom="@id/pass_input"
                android:layout_alignRight="@id/pass_input"
                android:layout_alignEnd="@id/pass_input"
                android:layout_marginBottom="15dp"
                />
         <!--   <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_below="@id/pass_input"
                android:id="@+id/email_input"
                android:hint="@string/email_hint"
                android:layout_height="wrap_content">
                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:inputType="textEmailAddress"
                    android:textColor="@color/Dark"
                    android:drawableRight="@drawable/ic_email_blue_24dp"
                    android:drawableEnd="@drawable/ic_email_blue_24dp"
                    android:id="@+id/EmailEditText"/>
            </android.support.design.widget.TextInputLayout>   -->


            <android.support.design.widget.TextInputLayout
                android:layout_width="match_parent"
                android:layout_below="@id/pass_input"
                android:id="@+id/pass_input_confirm"
                android:hint="@string/password_hint"
                android:layout_height="wrap_content">
                <EditText
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:inputType="textPassword"
                    android:textColor="@color/Dark" />
                  <!--  android:id="@+id/PassEditText1" -->
            </android.support.design.widget.TextInputLayout>
            <ImageButton
                android:id="@+id/pass_view_1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="@drawable/ic_pass_eye_blue_24dp"
                android:layout_alignBottom="@id/pass_input_confirm"
                android:layout_alignRight="@id/pass_input"
                android:layout_alignEnd="@id/pass_input"
                android:layout_marginBottom="15dp"
                />

       <!--    <CheckBox
                android:id="@+id/ageCheckBox"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignLeft="@id/pass_input"
                android:layout_alignStart="@id/pass_input"
                android:textColor="@color/dimGray"
                android:textStyle="bold"
                android:layout_below="@id/pass_input_confirm"
                android:text="@string/age_checkbox"/> -->
        </RelativeLayout>
    </android.support.v7.widget.CardView>
    <Button
        style="@android:style/Widget.Holo.Button.Small"
        android:id="@+id/CreateButton"
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:layout_below="@id/sign_up_layout"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="202dp"
        android:text="@string/sign_up"
        android:textColor="@color/White"
        android:background="@drawable/sign_up_bg"/>

    <TextView
        android:id="@+id/TermsTextView"
        android:layout_below="@id/CreateButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/terms_text_view_text"
        android:textColor="@color/LightGray"
        android:maxLines="2"
        android:layout_centerHorizontal="true"
        android:layout_margin="20dp"
        android:gravity="center"
        />

</RelativeLayout>

`

Ответы [ 2 ]

0 голосов
/ 06 января 2020

Установите эти идентификаторы email_input, pass_input и pass_input_confirm на EditText вместо TextInputLayout и измените свой код соответственно, как показано ниже:

EditText edtUsername, edtPassword, edtConfirmPassword;

@Override
public void onClick(View v) {

    if (isEmpty(edtUsername.getText().toString()) ||
            isEmpty(edtPassword.getText().toString()) ||
            isEmpty(edtConfirmPassword.getText().toString()))
        ShowSnackBar("Please enter all fields");
    else if (!edtPassword.getText().toString().equals(edtConfirmPassword.getText().toString()))
        ShowSnackBar("Password does not match");
    else {
        AddUsers addUsers = new AddUsers();
        addUsers.execute("");
    }
}
0 голосов
/ 06 января 2020

Удалить TextInputLayout и просто сохранить EditText просмотр. Проблема заключается в том, что вы используете getEditText(), то есть child() из EditText на TextInputLayout. Следовательно, исключение gettign nullpointer.

...