Asking Solution for Login Activity : **When I press Login Button it shows (Username/Password Wrong) even if i put the right Username & password. It doesn't go to next Activity. the Sing up activity is working fine. i am not able to solve this problem. if anyone can find the problem it would be very helpful. This is my 1st android studio work.**


MainActivity

    public class MainActivity extends AppCompatActivity {
    private Button signup;
    DatabaseHelper helper = new DatabaseHelper(this);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        signup = (Button) findViewById(R.id.Bsignup);

        signup.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent button = new Intent(MainActivity.this, SignUp.class);
                MainActivity.this.startActivity(button);
            }
        });
    }

    public void onButtonClick(View v) {
        if (v.getId() == R.id.BLogin) {

            EditText a = (EditText) findViewById(R.id.TFusername);
            String str = a.getText().toString();
            EditText b = (EditText) findViewById(R.id.TFpassword);
            String pass = b.getText().toString();

            String password = helper.searchPass(str);
            if (password.equals(pass)) {

                Intent i = new Intent(MainActivity.this, Display.class);
                i.putExtra("Username", str);
                startActivity(i);

            }else{

                Toast temp = Toast.makeText(MainActivity.this, "Username/Password Wrong", Toast.LENGTH_LONG);
                temp.show();

            }
        }
    }}


SignupActivity

    public class SignUp extends AppCompatActivity {

    DatabaseHelper helper = new DatabaseHelper(this);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sign_up);
    }

    public void onSignUpClick(View v){
        if(v.getId()== R.id.Bsignupbutton){
            EditText name = (EditText) findViewById(R.id.TFname);
            EditText uname = (EditText) findViewById(R.id.TFuname);
            EditText phone = (EditText) findViewById(R.id.TFphone);
            EditText pass1 = (EditText) findViewById(R.id.TFpass1);
            EditText pass2 = (EditText) findViewById(R.id.TFpass2);

            String namestr = name.getText().toString();
            String unamestr = uname.getText().toString();
            String phonestr = phone.getText().toString();
            String pass1str = pass1.getText().toString();
            String pass2str = pass2.getText().toString();

            if (!pass1str.equals(pass2str)){
                Toast pass = Toast.makeText(SignUp.this, "Password doesn't match", Toast.LENGTH_LONG);
                pass.show();
            }else{

                Contact c = new Contact();
                c.setName(namestr);
                c.setUname(unamestr);
                c.setPhone(phonestr);
                c.setPass(pass1str);

                helper.insertContact(c);

                Toast.makeText(getApplicationContext(), "Registration Successful", Toast.LENGTH_LONG).show();
                startActivity(new Intent(this, MainActivity.class));
            }
        }
    }}


DatabaseHelper

    public class DatabaseHelper extends SQLiteOpenHelper {

    private static final int DATABASE_VERSION = 1;
    private static final String DATABASE_NAME = "contacts.db";
    private static final String TABLE_NAME = "contacts";
    private static final String COLUMN_ID = "id";
    private static final String COLUMN_NAME = "name";
    private static final String COLUMN_UNAME = "uname";
    private static final String COLUMN_PHONE = "phone";
    private static final String COLUMN_PASS = "pass";
    SQLiteDatabase db;


    public DatabaseHelper(Context context)
    {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }
    private static final String TABLE_CREATE = "create table contacts (id integer primary key not null , " +
            "name text not null , uname text not null , phone text not null, pass text not null);";
    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(TABLE_CREATE);
        this.db = db;
    }
    public void insertContact(Contact c) {
        db = this.getWritableDatabase();
        ContentValues values = new ContentValues();

        String query = "select * from contacts";
        Cursor cursor = db.rawQuery(query, null);
        int count = cursor.getCount();

        values.put(COLUMN_ID, count);
        values.put(COLUMN_NAME, c.getName());
        values.put(COLUMN_UNAME, c.getUname());
        values.put(COLUMN_PHONE, c.getPhone());
        values.put(COLUMN_PASS, c.getPass());

        db.insert(TABLE_NAME , null  , values);

    }

    public String searchPass(String uname)
    {
        db= this.getReadableDatabase();
        String query = "select uname, pass from "+TABLE_NAME;
        Cursor cursor = db.rawQuery(query, null);
        String a, b;
        b = "not found";
        if (cursor.moveToFirst())
        {
            do{
                a = cursor.getString(0);

                if (a.equals(uname))
                {

                    b = cursor.getString(1);
                    break;
                }
            }
            while(cursor.moveToNext());
        }
        return b;
    }
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        String query = "DROP TABLE IF EXISTS " + TABLE_NAME;
        db.execSQL(query);
        this.onCreate(db);
    }}



  [1]: https://i.stack.imgur.com/eZuRS.png