I have the following error
E/AndroidRuntime: FATAL EXCEPTION: main
Process: shop.easy.app.x.com.x, PID: 10183
java.lang.RuntimeException: Unable to start activity ComponentInfo{shop.easy.app.x.com.x/shop.easy.app.x.com.x.Acceso}: java.lang.ClassCastException: android.support.v7.widget.AppCompatAutoCompleteTextView cannot be cast to com.rengwuxian.materialedittext.MaterialEditText
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Caused by: java.lang.ClassCastException: android.support.v7.widget.AppCompatAutoCompleteTextView cannot be cast to com.rengwuxian.materialedittext.MaterialEditText
at shop.easy.app.x.com.x.Acceso.onCreate(Acceso.java:35)
at android.app.Activity.performCreate(Activity.java:6975)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
Specifically in this part
Caused by: java.lang.ClassCastException: android.support.v7.widget.AppCompatAutoCompleteTextView cannot be cast to com.rengwuxian.materialedittext.MaterialEditTextat shop.easy.app.x.com.x.Access.onCreate(Access.java:35 )
The Access Code.xml
package shop.easy.app.x.com.x;
import android.app.ProgressDialog;
import android.content.Intent;
import android.hardware.usb.UsbInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.rengwuxian.materialedittext.MaterialEditText;
import shop.easy.app.x.com.x.Common.Common;
import shop.easy.app.x.com.x.model.Usuario;
public class Acceso extends AppCompatActivity {
EditText edtPhone,edtPassword;
Button btnSignIn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edtPhone = (MaterialEditText)findViewById(R.id.edtPhone);
edtPassword = (MaterialEditText)findViewById(R.id.edtPassword);
btnSignIn = (Button)findViewById(R.id.btnSignIn);
//init firebase
final FirebaseDatabase database = FirebaseDatabase.getInstance();
final DatabaseReference table_user = database.getReference("Usuario");
btnSignIn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
final ProgressDialog mDialog = new ProgressDialog(Acceso.this);
mDialog.setMessage("Por favor espera...");
mDialog.show();
table_user.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//comprobar si el usuario no existe en la base de datos
if (dataSnapshot.child(edtPhone.getText().toString()).exists()) {
//Informacion usuario
mDialog.dismiss();
Usuario usuario = dataSnapshot.child(edtPhone.getText().toString()).getValue(Usuario.class);
if (usuario.getContraseña().equals(edtPassword.getText().toString())) {
{
Intent homeintent = new Intent(Acceso.this,Inicio.class);
Common.currentUsuario = usuario;
startActivity(homeintent);
finish();
}
} else {
Toast.makeText(Acceso.this, "Constraseña incorrecta !!", Toast.LENGTH_SHORT).show();
}
}
else
{
mDialog.dismiss();
Toast.makeText(Acceso.this, "Usuario no registrado en base de dato", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
});
}
}
xml code
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="@drawable/rectangulo_trans_blanco"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:paddingStart="15dp"
android:text="Usuario"
android:textColor="@color/white"
android:textSize="22sp"
android:textStyle="italic" />
<AutoCompleteTextView
android:id="@+id/edtPhone"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="15dp"
android:layout_marginEnd="15dp"
android:layout_marginStart="15dp"
android:background="@drawable/barratrasparente"
android:hint="958439457"
android:paddingStart="15dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="15dp"
android:text="Contraseña"
android:textColor="@color/white"
android:textSize="22sp" />
<AutoCompleteTextView
android:id="@+id/edtPassword"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginBottom="15dp"
android:layout_marginEnd="15dp"
android:layout_marginStart="15dp"
android:background="@drawable/barratrasparente"
android:hint="********"
android:inputType="textPassword"
android:paddingStart="15dp"
android:layout_marginVertical="0sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginBottom="-10sp"
android:layout_gravity="right"
android:paddingEnd="20dp"
android:text="¿Recordar Contraseña?"
android:textColor="@color/white"
android:textSize="17sp" />
<Button
android:id="@+id/btnSignIn"
android:layout_width="300dp"
android:layout_height="53dp"
android:layout_above="@+id/btnSignIn"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="10dp"
android:layout_marginTop="15dp"
android:background="@drawable/botonestilo1"
android:text="Iniciar Seción"
android:textColor="@android:color/white" />
<Button
android:id="@+id/btnSignUp"
android:layout_width="300dp"
android:layout_height="53dp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="0dp"
android:background="@drawable/botonestilo2"
android:text="Registrarse"
android:textColor="@android:color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="¿Olvidaste tu contraseña? restablecer aquí"
android:textColor="@color/white"
android:textSize="16sp"
android:layout_marginVertical="4dp"
android:layout_gravity="center_horizontal"/>
</LinearLayout>
</ScrollView>
You are instantiating type variables
EditText
with instances of typeMaterialEditText
.To solve your problem the variables must be of the same type as the instances.
edited
The problem is that you are casting objects of type
MaterialEditText
with objects of typeEditText
.The solution to the problem is to do type casting
EditText