I'm having trouble comparing strings. One retreat from one EditText and the other from an SQL table. The app consists of a game of the genre " Who wants to be a millionare? "
When it arrives at the if cycle of comparison between the two strings:
if (pass_jogador == verifica_pass) {...
passes directly to the corresponding else .
When I use the application and enter the data, I use a Toast to check if the two strings are the same:
apresenta_toast(verifica_pass);
apresenta_toast(pass_jogador);
and the result is the same, they indicate that the strings are the same.
Here is my code in full:
int id = v.getId();
if (id == btn_login.getId()) {
//verificar se jogador existe
//verificar a password
//faz login
String verifica_email = this.email.getText().toString();
String verifica_pass = this.password.getText().toString();
if (verifica_email != null && verifica_pass != null) {
MyDBHelper dbHelper = new MyDBHelper(this);
SQLiteDatabase db = dbHelper.getWritableDatabase();
Cursor cursor = db.rawQuery("SELECT * FROM Jogador WHERE email_jogador = '" + verifica_email + "'", null);
if (cursor != null && cursor.moveToFirst()) {
String pass_jogador = cursor.getString(2);
//verifica a igualdade das passwords
apresenta_toast(verifica_pass);
apresenta_toast(pass_jogador);
if (pass_jogador == verifica_pass) {
Jogador player = criaJogador(cursor, db);
Intent myIntent = new Intent(this, MenuActivity.class);
startActivity(myIntent);
Here is the table and user data I entered by default:
db.execSQL("CREATE TABLE Jogador (email_jogador VARCHAR(50) PRIMARY KEY, nome VARCHAR(50) NOT NULL, password VARCHAR(50) NOT NULL, genero VARCHAR(50) NOT NULL, status VARCHAR(50) NOT NULL, pontuacao INTEGER, perguntasC INTEGER)");
db.execSQL("INSERT INTO Jogador(email_jogador, nome, password, genero, status, pontuacao, perguntasC) VALUES ('[email protected]', 'Zé', 'qwerty', 'masculino','dealer', 0, 0)");