Home > Software design >  how to solve an app crash error in andriod studio
how to solve an app crash error in andriod studio

Time:03-16

Caused by: java.lang.ClassCastException: com.google.android.material.textfield.TextInputLayout cannot be cast to com.google.android.material.textfield.TextInputEditText at com.example.cpp_project.Dashboard.onCreate(Dashboard.java:29)

(Dashboard.java:29) = username=findViewById(R.id.username);

CodePudding user response:

TextInputLayout username = findViewById(R.id.username);

CodePudding user response:

ClassCastException is a runtime exception raised in Java when we try to improperly cast a class from one type to another.

In most cases -- depending on compiler support -- the resulting view is automatically cast to the target class type. If the target class type is unconstrained, an explicit cast may be necessary.

for example:

EditText editText = (EditText)findViewById(R.id.username);

for more info you can look at here in docs findViewById and TextInputLayout

CodePudding user response:

Try to cast from TextInputLayout to TextInputEditText

username = (TextInputEditText)findViewById(R.id.username);
  • Related