I created a simple login page with validations but i have a problem in the password section when i want to use passwordToggleEnabled the app crash and don't open no idea why since i have 0 errors.
My project in on API 26.
I have added in build gradle inside dependicies:
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
And inside the XML file this is my code of password input:
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/test2"
android:layout_below="@id/usernameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
app:errorEnabled="true"
app:passwordToggleEnabled="true">
<com.google.android.material.textfield.TextInputEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Your Password"
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>
and in MainActivity.java this is how i am calling the id of pwd:
String passwordInput = test2.getText().toString().trim();
So this is how am implementing my code and the app keeps stopping so what i am doing wrong ?
Thank you!
Use the method getEditText
to get the EditText
used for text input:
TextInputLayout test2= findViewById(R.id.test2);
String passwordInput = test2.getEditText().getText().toString().trim();