title: How to fix casting androidx.appcompat.widget.AppCompatButton cannot be cast to com.google.android.material.textfield.TextInputLayout
body: <p>My code was working fine but today after the running gave me the next error:</p>
  
  <p>androidx.appcompat.widget.AppCompatButton cannot be cast to com.google.android.material.textfield.TextInputLayout</p>
  
  <p>The error at line 92 :    <code>verify_code = findViewById(R.id.verify_code);</code></p>
  
  <p>The application breaks when the activity started , and i got the following error</p>
  
  <p>The java code </p>
  
  <pre><code>
  public class PhoneLoginActivity extends AppCompatActivity {
      private EditText InputUserPhoneNumber, InputUserVerificationCode;
      private Button SendVerificationCodeButton, VerifyButton;
      private long backPressedTime;
      private Toast backToast;
      ProgressDialog progressDialog;
      private PhoneAuthProvider.OnVerificationStateChangedCallbacks callbacks;
      private FirebaseAuth mAuth;
      private TextInputLayout phone_num;
      private TextInputLayout verify_code;
      private ProgressDialog loadingBar;
      private DatabaseReference dbRef;
      private FirebaseDatabase mFirebaseDatabase;
      private String mVerificationId;
      String lat;
      private StorageReference mStorageRef;
      String uid;
      String lng;
      String phone_number;
      private PhoneAuthProvider.ForceResendingToken mResendToken;
      public static final int Request_Code_Granded_Premission = 1408;
      private static final String TAG = "PhoneLoginActivity";
      private String ph_num;
      boolean check = false;
      private String phone_jor;
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_login);
  
          mStorageRef = FirebaseStorage.getInstance().getReference();
  
          mFirebaseDatabase = FirebaseDatabase.getInstance();
          dbRef = mFirebaseDatabase.getReference("Guest");
          InputUserPhoneNumber = (EditText) findViewById(R.id.phone_text);
          InputUserVerificationCode = (EditText) findViewById(R.id.pwd_text);
          SendVerificationCodeButton = (Button) findViewById(R.id.login_btn);
          VerifyButton = (Button) findViewById(R.id.verify_button);
          loadingBar = new ProgressDialog(this);
          phone_num = findViewById(R.id.phone_number);
          verify_code = findViewById(R.id.verify_code);
  
          phone_number = InputUserPhoneNumber.getText().toString();
  
      .
      .
      .
  
  
              }
  
  }
  
  
  </code></pre>
  
  <p>The xml code </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout
      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"
      android:background="#fff"
      android:id="@+id/log_in"
      android:scrollbars="vertical"
      android:paddingBottom="30dp"
      tools:context=".Activities.PhoneLoginActivity"
      xmlns:android="http://schemas.android.com/apk/res/android"&gt;
  
  
      &lt;ImageView
          android:id="@+id/circle"
          android:layout_width="146dp"
          android:layout_height="121dp"
          android:layout_centerHorizontal="true"
          android:layout_marginTop="20dp"
  
          app:srcCompat="@drawable/circle_logo" /&gt;
  
  
      &lt;TextView
  
          android:id="@+id/hello"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginLeft="5dp"
          android:layout_below="@+id/circle"
          android:layout_centerHorizontal="true"
          android:layout_marginRight="5dp"
          android:layout_marginTop="10dp"
          android:gravity="center"
          android:text="@string/hello_word"
          android:textSize="14dp" /&gt;
  
  
  
  
      &lt;TextView
          android:layout_below="@+id/hello"
  
          android:id="@+id/hello2"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_marginLeft="5dp"
          android:layout_centerHorizontal="true"
          android:layout_marginRight="5dp"
          android:layout_marginTop="25dp"
          android:textColor="#000"
          android:gravity="center"
          android:text="@string/hello2"
          android:textSize="14dp" /&gt;
  
  
      &lt;LinearLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_below="@id/hello2"
          android:gravity="top|center"
          android:layout_marginTop="5dp"
          android:orientation="vertical"
          android:layout_marginRight="10dp"
          android:layout_marginLeft="10dp"
  
          &gt;
  
          &lt;com.google.android.material.textfield.TextInputLayout
              android:id="@+id/phone_number"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_gravity="center"
              android:theme="@style/TextLabel"&gt;
  
  
              &lt;com.google.android.material.textfield.TextInputEditText
                  android:id="@+id/phone_text"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:layout_marginBottom="15dp"
                  android:ems="10"
                  android:hint="@string/ed_phone"
                  android:inputType="phone"
                  android:textColor="#064065"
                  android:textColorHint="#064065"
                   /&gt;
          &lt;/com.google.android.material.textfield.TextInputLayout&gt;
  
          &lt;com.google.android.material.textfield.TextInputLayout
              android:id="@+id/verify_code"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_marginTop="-75dp"
              android:layout_marginBottom="15dp"
              android:gravity="center"
              android:theme="@style/TextLabel"
              android:visibility="invisible"&gt;
  
              &lt;com.google.android.material.textfield.TextInputEditText
                  android:id="@+id/pwd_text"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content"
                  android:ems="10"
                  android:hint="@string/ed_pwd"
                  android:inputType="number"
  
                  android:textColor="#064065"
                  android:textColorHint="#064065"
                /&gt;
  
          &lt;/com.google.android.material.textfield.TextInputLayout&gt;
  
  
          &lt;Button
  
              android:id="@+id/login_btn"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_marginBottom="2dp"
              android:background="@drawable/btn_login"
              android:text="@string/login"
              android:textColor="@android:color/white"
  
              /&gt;
  
          &lt;Button
  
              android:id="@+id/verify_button"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_marginTop="-50dp"
              android:text="@string/verify"
              android:textColor="@android:color/black"
  
              android:visibility="invisible" /&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>And The erorr </p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
      Process: com.awshakam1998.bottleofwater, PID: 31185
      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.awshakam1998.bottleofwater/com.awshakam1998.bottleofwater.Activities.PhoneLoginActivity}: java.lang.ClassCastException: androidx.appcompat.widget.AppCompatButton cannot be cast to com.google.android.material.textfield.TextInputLayout
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3194)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3302)
          at android.app.ActivityThread.-wrap12(Unknown Source:0)
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1891)
          at android.os.Handler.dispatchMessage(Handler.java:108)
          at android.os.Looper.loop(Looper.java:166)
          at android.app.ActivityThread.main(ActivityThread.java:7425)
          at java.lang.reflect.Method.invoke(Native Method)
          at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
       Caused by: java.lang.ClassCastException: androidx.appcompat.widget.AppCompatButton cannot be cast to com.google.android.material.textfield.TextInputLayout
          at com.awshakam1998.bottleofwater.Activities.PhoneLoginActivity.onCreate(PhoneLoginActivity.java:92)
          at android.app.Activity.performCreate(Activity.java:7372)
          at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1218)
          at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3147)
          at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3302) 
          at android.app.ActivityThread.-wrap12(Unknown Source:0) 
          at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1891) 
          at android.os.Handler.dispatchMessage(Handler.java:108) 
          at android.os.Looper.loop(Looper.java:166) 
          at android.app.ActivityThread.main(ActivityThread.java:7425) 
          at java.lang.reflect.Method.invoke(Native Method) 
          at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245) 
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921) 
  </code></pre>