0

First sorry for my poor english :)

I click button but app close automaticly

I want if user exist database , read editttext "exist"

Database activity code:

public Boolean varmi(String KULLANICI) {
    // TODO Auto-generated method stub

    Cursor c = DB_Database.query(DATABASE_TABLOSU, kolonlar, K_ADI + "=" + KULLANICI, null, null, null, null);

    if(c.moveToFirst()){
        return true;
    }
    else{
        return null;
    }
}

Main activity code:

buttonGiris.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            String KULLANICI=editKullanici.getText().toString();
            db.dbyiac();
            if(db.varmi(KULLANICI) != null){
                textBilgiler.setText("User exist");
            }
            else{textBilgiler.setText("User don't exist");}
            db.dbyikapat();


        }
androboy
  • 356
  • 1
  • 2
  • 9
  • Stacktrace, please. http://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – laalto Dec 28 '14 at 18:17

2 Answers2

1

String literals in SQL must be in single quotes. Better yet, use ? literal placeholder and argument binding:

Cursor c = DB_Database.query(DATABASE_TABLOSU, kolonlar, K_ADI + "=?", new String[] { KULLANICI }, null, null, null);
laalto
  • 150,114
  • 66
  • 286
  • 303
0

cursor.getColumnIndex(String columnName) returns -1 if, the column doesn't exist :) and call this method textBilgiler.setText("User don't exist"); :) kolay gele.

previousdeveloper
  • 315
  • 2
  • 6
  • 12