Hrishikesh Deshpande
Hrishikesh Deshpande

Reputation: 29

Why does the button say as an invalid button type?

I am creating a Social media app with firebase to store data.When the app is build an illegal java exception is shown saying:- View 'button' with ID 2131165271 for field 'mButton' was of the wrong type. See ca use for more info. package com.example.whatareyouthinking;

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

import android.os.Bundle; import android.view.View; import android.widget.EditText; import android.widget.Toast;

import com.google.android.gms.tasks.OnCompleteListener; import com.google.android.gms.tasks.Task; import com.google.firebase.auth.AuthResult; import com.google.firebase.auth.FirebaseAuth; import com.google.firebase.firestore.CollectionReference; import com.google.firebase.firestore.FirebaseFirestore;

import java.util.HashMap; import java.util.Map;

import butterknife.BindView; import butterknife.ButterKnife;

public class MainActivity extends AppCompatActivity {

@BindView(R.id.name)EditText mNameEt;
@BindView(R.id.email)EditText mEmailEt;
@BindView(R.id.password)EditText mPasswordEt;
@BindView(R.id.button)EditText mButton;
private String name,email,password;
private FirebaseAuth mAuth;

private CollectionReference mRef;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    mAuth=FirebaseAuth.getInstance();
    mRef= FirebaseFirestore.getInstance().collection("Users");

    mButton.setOnClickListener(v -> checkDataAndLogin());
}
private void checkDataAndLogin(){
    name=mNameEt.getText().toString();
    email=mEmailEt.getText().toString().trim();
    password=mPasswordEt.getText().toString().trim();

    if(name.isEmpty()||email.isEmpty()||password.length()<6){
        Toast.makeText(getApplicationContext(),"Invalid Credentials",Toast.LENGTH_SHORT).show();
    }
    else{
        mAuth.createUserWithEmailAndPassword(email,password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
            @Override
            public void onComplete(@NonNull Task<AuthResult> task) {
                if (!task.isSuccessful()){
                    Toast.makeText(getApplicationContext(),task.getException().getLocalizedMessage(),Toast.LENGTH_LONG).show();
                }
                else {
                    saveUserData();
            }
            }

        });

    }
}
private void saveUserData(){
    Map<String,String> map =new HashMap<>();
    map.put("name",name);
    map.put("email",email);
    map.put("password",password);
    map.put("id",mAuth.getUid());
    mRef.document(mAuth.getUid()).set(map).addOnCompleteListener(new OnCompleteListener<Void>() {
        @Override
        public void onComplete(@NonNull Task<Void> task) {
            if(!task.isSuccessful()){
                Toast.makeText(getApplicationContext(),task.getException().getLocalizedMessage(),Toast.LENGTH_SHORT).show();
            }else{
                Toast.makeText(getApplicationContext(),"SignUp Successful",Toast.LENGTH_SHORT).show();
            }
        }
    });

} }

This is my code for Mainactivity what is the issue with mbutton can anyone help?

Upvotes: 1

Views: 92

Answers (1)

David Kroukamp
David Kroukamp

Reputation: 36423

This here:

@BindView(R.id.button)EditText mButton;

Should be:

@BindView(R.id.button)Button mButton;

Upvotes: 2

Related Questions