-1
I am making a login page that if the data is correct or incorrect appears a Toast displaying the result.
The problem is that there is no error (when there is any) and when run in the emulator the application stops working.
Code:
package com.example.appteste;
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;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private login mLogin = new login();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.mLogin.nome = findViewById(R.id.nome);
this.mLogin.senha = findViewById(R.id.senha);
this.mLogin.button.setOnClickListener(this);
}
@Override
public void onClick(View view) {
if ("Arthur" == this.mLogin.nome.getText().toString() & "123" == this.mLogin.senha.getText().toString()) {
Toast.makeText(this, "Usuario e senha correto!", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "Usuario ou senha incorretos!", Toast.LENGTH_LONG).show();
}
}
private static class login {
EditText nome;
EditText senha;
Button button;
}
}
You have to show the stack error, so you have the error cause, try to convert the parameters to: this.mLogin.name = (Edittext) findViewById(R.id.name);
– fernando
Emulator error: http://prntscr.com/o9r9vz Console error: put in post
– Arthur BL
I did what you said and gave the same problem.
– Arthur BL
Just remove this.mLogin.button.setOnClickListener(this); The app opens no more I can’t run the event without that line.
– Arthur BL
Add this line node method onCreate this.mLogin.button = (Button) findViewById(R.Id.button); button must be the name of the variable that is your XML node.
– fernando