Stormy Chase Forrester Stormy Chase Forrester - 2 months ago 6
Android Question

Incovertable types; Canot cast 'android.view.View' to int'

The Phone and etAdress are coming up with the error below:


Canot cast 'android.view.View' to int'


public class register extends AppCompatActivity {

private EditText Name;
private int Phone;
private EditText etEmailUser;
private EditText Address;
private EditText txtPassword;
private FirebaseAuth firebaseAuth;@
Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
Name = (EditText) findViewById(R.id.etName);
Phone = (int) findViewById(R.id.etPhone);
etEmailUser = (EditText) findViewById(R.id.etEmailUser);
etAddress = (EditText) findViewById(R.id.etAddress);
firebaseAuth = FirebaseAuth.getInstance();
}


What am I doing wrong?

Answer

The reason is findViewById(R.id.etPhone) will return a View not an int. In your case I think etPhone is an EditText so you should change Phone type to EditText

private EditText Phone;
...
     Phone = (EditText) findViewById(R.id.etPhone);