javaandroidcrashruntime-errorruntimeexception

My app crashes and don't start the signup activity


i have tried everything when i run the app it runs but signup activity crashes and come back to the welcome screen.tell me what's the problem whether i'm doing something wrong or it's any other problem. this is signup activity code im using firebase

package com.example.chatzone;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.android.material.textfield.TextInputEditText;
import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;

public class SignUp extends AppCompatActivity {

    TextInputEditText UserName;
    TextInputEditText Email;
    TextInputEditText Pass01;
    TextInputEditText conPass01;
    Button signUp;
    String emailPattern = "[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+";

    FirebaseAuth mAuth;
    FirebaseUser mUser;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sign_up);
        UserName=findViewById(R.id.Username);
        Email=findViewById(R.id.Email);
        Pass01=findViewById(R.id.Password01);
        conPass01=findViewById(R.id.Password02);
        signUp=findViewById(R.id.Sign_Up02);
        mAuth=FirebaseAuth.getInstance();
        mUser=mAuth.getCurrentUser();

        signUp.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               creatUser();
            }

            private void creatUser() {
                Intent i = getIntent();
                String BD = i.getStringExtra(userInfo.t1);
                String FN = i.getStringExtra(userInfo.t2);
                String LN = i.getStringExtra(userInfo.t3);
                String PN = i.getStringExtra(userInfo.t4);
                String email=Email.getText().toString();
                String UN=UserName.getText().toString();
                String Pass=Pass01.getText().toString();
                String conPass=conPass01.getText().toString();
                if(!email.matches(emailPattern)){
                    Toast.makeText(SignUp.this,"Enter valid Email Address",Toast.LENGTH_SHORT).show();
                }else if(Pass == conPass)
                {
                    Toast.makeText(SignUp.this,"Password and Confirm Password does not match",Toast.LENGTH_SHORT).show();
                }else if(Pass.length()<6){
                    Toast.makeText(SignUp.this,"Password length should be Atleast 6 digit long",Toast.LENGTH_SHORT).show();
                }else if(TextUtils.isEmpty(email) || TextUtils.isEmpty(UN) || TextUtils.isEmpty(Pass) || TextUtils.isEmpty(conPass))
                {
                    Toast.makeText(SignUp.this,"Input Field can't be Empty",Toast.LENGTH_SHORT).show();
                }else
                {
                    mAuth.createUserWithEmailAndPassword(email,Pass).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                        @Override
                        public void onComplete(@NonNull Task<AuthResult> task) {
                            if(task.isSuccessful())
                            {
                                Toast.makeText(SignUp.this,"Registration Successful",Toast.LENGTH_SHORT).show();
                                nextAct();
                            }
                            else{
                                Toast.makeText(SignUp.this,""+task.getException(),Toast.LENGTH_SHORT).show();
                            }
                        }
                    });
                }
                
            }

            private void nextAct() {
                Intent in = new Intent(SignUp.this,MainActivity.class);
                startActivity(in);
            }
        });
    }



}

this is the error

FATAL EXCEPTION: main
Process: com.example.chatzone, PID: 30802
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.chatzone/com.example.chatzone.SignUp}: java.lang.ClassCastException: com.google.android.material.textfield.TextInputLayout cannot be cast to com.google.android.material.textfield.TextInputEditText
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3754)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3912)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2319)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:239)
    at android.app.ActivityThread.main(ActivityThread.java:8212)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:626)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1016)
Caused by: java.lang.ClassCastException: com.google.android.material.textfield.TextInputLayout cannot be cast to com.google.android.material.textfield.TextInputEditText
    at com.example.chatzone.SignUp.onCreate(SignUp.java:35)
    at android.app.Activity.performCreate(Activity.java:8119)
    at android.app.Activity.performCreate(Activity.java:8103)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1359)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3727)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3912) 
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) 
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) 
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2319) 
    at android.os.Handler.dispatchMessage(Handler.java:106) 
    at android.os.Looper.loop(Looper.java:239) 
    at android.app.ActivityThread.main(ActivityThread.java:8212) 
    at java.lang.reflect.Method.invoke(Native Method) 
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:626) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1016)  

the logcat is showing this type of error please help me solve this

Xml cod:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".SignUp">

    <TextView
        android:id="@+id/step2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="50dp"
        android:fontFamily="@font/knewave01"
        android:text="Step 02: "
        android:textColor="#808080"
        android:textSize="50dp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/Usertxt"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/step2"
        android:layout_marginStart="15dp"
        android:layout_marginTop="10dp"
        android:fontFamily="@font/knewave01"
        android:text="User Info: "
        android:textColor="@color/CZColor"
        android:textSize="40sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/UserNameText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/Usertxt"
        android:layout_marginStart="15dp"
        android:layout_marginTop="10dp"
        android:text="Username:"
        android:textColor="@color/black"
        android:textSize="20dp"
        android:textStyle="bold"></TextView>

    <com.google.android.material.textfield.TextInputLayout
        android:layout_marginStart="15dp"
        android:layout_width="360dp"
        android:layout_height="wrap_content"
        android:id="@+id/Username"
        android:hint="Username"
        app:startIconDrawable="@drawable/user"
        app:endIconMode="clear_text"
        app:endIconTint="#808080"
        app:boxStrokeColor="@color/CZColor"
        android:layout_below="@id/UserNameText">
        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textColor="@color/CZColor">
        </com.google.android.material.textfield.TextInputEditText>
    </com.google.android.material.textfield.TextInputLayout>

    <TextView
        android:id="@+id/EmailText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/Username"
        android:layout_marginStart="15dp"
        android:layout_marginTop="10dp"
        android:text="Email:"
        android:textColor="@color/black"
        android:textSize="20dp"
        android:textStyle="bold"></TextView>

    <com.google.android.material.textfield.TextInputLayout
        android:layout_marginStart="15dp"
        android:layout_width="360dp"
        android:layout_height="wrap_content"
        android:hint="Email"
        android:id="@+id/Email"
        app:startIconDrawable="@drawable/email"
        app:endIconMode="clear_text"
        app:endIconTint="#808080"
        app:boxStrokeColor="@color/CZColor"
        android:layout_below="@id/EmailText">
        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textColor="@color/CZColor"
            android:inputType="textEmailAddress">
        </com.google.android.material.textfield.TextInputEditText>
    </com.google.android.material.textfield.TextInputLayout>

    <TextView
        android:id="@+id/PasswordText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/Email"
        android:layout_marginStart="15dp"
        android:layout_marginTop="10dp"
        android:text="Password:"
        android:textColor="@color/black"
        android:textSize="20dp"
        android:textStyle="bold"></TextView>

    <com.google.android.material.textfield.TextInputLayout
        android:layout_marginStart="15dp"
        android:layout_width="360dp"
        android:layout_height="wrap_content"
        android:hint="Password"
        android:id="@+id/Password01"
        app:startIconDrawable="@drawable/key"
        app:endIconMode="password_toggle"
        app:endIconTint="#808080"
        app:boxStrokeColor="@color/CZColor"
        android:layout_below="@id/PasswordText">
        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textColor="@color/CZColor"
            android:inputType="textPassword">
        </com.google.android.material.textfield.TextInputEditText>
    </com.google.android.material.textfield.TextInputLayout>

    <TextView
        android:id="@+id/PasswordText01"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/Password01"
        android:layout_marginStart="15dp"
        android:layout_marginTop="10dp"
        android:text="Confirm Password:"
        android:textColor="@color/black"
        android:textSize="20dp"
        android:textStyle="bold"></TextView>

    <com.google.android.material.textfield.TextInputLayout
        android:layout_marginStart="15dp"
        android:layout_width="360dp"
        android:layout_height="wrap_content"
        android:hint="Confirm Password"
        android:id="@+id/Password02"
        app:startIconDrawable="@drawable/key"
        app:endIconMode="clear_text"
        app:endIconTint="#808080"
        app:boxStrokeColor="@color/CZColor"
        android:layout_below="@id/PasswordText01">
        <com.google.android.material.textfield.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:textColor="@color/CZColor">
        </com.google.android.material.textfield.TextInputEditText>
    </com.google.android.material.textfield.TextInputLayout>

    <Button
        android:id="@+id/Sign_Up02"
        android:layout_width="170dp"
        android:layout_height="60dp"
        android:layout_centerHorizontal="true"
        android:layout_below="@id/Password02"
        android:layout_marginTop="15dp"
        android:text="SIGN UP"
        android:textSize="20dp"
        android:textStyle="bold" />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Already have account ?"
        android:textSize="22dp"
        android:textColor="#808080"
        android:textStyle="bold"
        android:layout_marginStart="50dp"
        android:layout_marginTop="10dp"
        android:layout_below="@+id/Sign_Up02"
        ></TextView>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Sign In"
        android:textSize="23dp"
        android:textColor="@color/CZColor"
        android:layout_marginStart="285dp"
        android:layout_marginTop="10dp"
        android:textStyle="bold"
        android:layout_below="@+id/Sign_Up02"
        ></TextView>

    <ImageButton
        android:id="@+id/imageButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="5dp"
        android:layout_marginTop="5dp"
        app:srcCompat="@drawable/back"
        android:background="@color/white"
        />
    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/progressBar01"
        android:indeterminate="true"
        android:layout_centerInParent="true"
        android:visibility="gone"></ProgressBar>
</RelativeLayout>

Solution

  • You can easily check why the problem in this log:

    Caused by: java.lang.ClassCastException: com.google.android.material.textfield.TextInputLayout cannot be cast to com.google.android.material.textfield.TextInputEditText

    You declare wrong view for variable Email. Try declare it with TextInputLayout.

    And one more thing, you shouldn't declare name of variable like "Email,Username,Pass01". It will cause your project more difficult to maintain. Find naming convention to know more about it