C
C
Chvalov2015-05-14 17:11:06
Java
Chvalov, 2015-05-14 17:11:06

How to make this code work, comparing strings and switching to the second android activity?

There is a DB in which the password is stored in open form and there is a text field.
I'm doing a case-insensitive comparison (There are only numeric values)
If you make comparisons and display its result, then everything works with a bang.
And to make it so that, with a positive result, switching to a new activity does not even compile.
What is the error is not clear (
There is a code:

public void OnClick_One (View view) {
        ExternalDbOpenHelper dbOpenHelper = new ExternalDbOpenHelper(this, DB_NAME);
        database = dbOpenHelper.getWritableDatabase();

        Cursor passwordCursor = database.query(TABLE_NAME,
                new String[]{PASS_ID, PASS_NAME},
                null, null, null, null,
                PASS_NAME);
        passwordCursor.moveToFirst();
        String pass = passwordCursor.getString(1);
        String EdText_Pass = EdText_EnterPassword.getText().toString();

        if(pass.equalsIgnoreCase(EdText_Pass))
            //TextView_EnterPassword.setText("Строки совпадают");

            Intent intent = new Intent(this, EnginesSettingsActivity.class);
            startActivity(intent);

        else
            TextView_EnterPassword.setText("Строки не совпадают");
        passwordCursor.close();
    }

Here is the error that comes up:
6b28788b4aae4802919a3c648d29a8a1.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nick Smith, 2015-05-14
@Chvalov

Syntax error, one expression can be used without parentheses.

if () {
Intent int = new Intent();
startActivity(int);
 } else {
//do something
}

C
Chvalov, 2015-05-14
@Chvalov

And also explain to me why this null is needed

new String[]{PASS_ID, PASS_NAME},
                null, null, null, null,
                PASS_NAME);

If I have this kind of
ID in the table - 1
pass - 142536
P.S. Is it possible here TextView_EnterPassword.setText("Lines don't match");
in setText to push the text which to be in strings.xml?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question