2017-07-03 17 views
-3

私はログインする必要があります。エラーはありませんが、 R.id.girisBtnを押すと、新しいアクティビティには移動しません。デバッグを進めました。 エラーが表示され、エラーが発生した元の場所私は理解しないAndroid SQLite _接続

DatabaseHelper.java

public class DatabaseHelper extends SQLiteOpenHelper{ 
    private static final int db_version=2; 
    private static final String db_Name="SosyalMedyaDB.db"; 
    private static final String db_table="Kisi"; 

    private static final int Index_UserName=0; 
    private static final int Index_UserPassword=1; 

//Db Create 

private static final String DATABASE_CREATE = "CREATE TABLE \"Kisi\" (
`isim` TEXT NOT NULL, `parola` TEXT, `email` TEXT, `cinsiyet` TEXT, `tarih` 
TEXT, `resim` INTEGER, " + 
     "`url` TEXT)"; 
SQLiteDatabase db; 
public DatabaseHelper(Context context) 
{ 
    super(context,db_Name,null,db_version); 
} 
@Override 
public void onCreate(SQLiteDatabase db) { 
    db.execSQL(DATABASE_CREATE); 
    this.db=db; 
    } 
public String searchPass(String usName) 
{ 
    db=this.getReadableDatabase(); 
    String query="select * from "+db_table; 
    Cursor cursor=db.rawQuery(query,null); 
    String a,b; 
    b="not found"; 
    if(cursor.moveToFirst()) 
    { 
     do { 
      a = cursor.getString(Index_UserName); 
      b=cursor.getString(Index_UserPassword); 
      if (a.equals(usName)) 
      { 
       b = cursor.getString(Index_UserPassword); 
       db.close(); 
     break; 
     }} 
      while (cursor.moveToNext()); 
     } 
     return b; 
    } 
@Override 
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) 
{ 
    db.execSQL("DROP TABLE IF EXISTS "+db_table); 
    this.onCreate(db); 
    } 
} 

Login.java

むしろこれより
public class Login extends AppCompatActivity { 
    EditText name,pass; 
    ArrayList<Kisi> uyeler; 
    String loginIsim, loginPass; 
    Intent intent; 
    DatabaseHelper dbHelper=new DatabaseHelper(this); 
    Button btnLogin; 
    String userName, userPassword; 
    @Override 
     protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_login); 

    name = (EditText) findViewById(R.id.loginName); 
    pass = (EditText) findViewById(R.id.password); 
    loginIsim = name.getText().toString(); 
    loginPass = pass.getText().toString(); 
     } 
    public void onClick(View v) { 
    switch (v.getId()) { 
     case R.id.girisBtn: 
      Log.w(".............. ",""); 
      String password = dbHelper.searchPass(loginIsim); 
      Log.w("string password ","................"); 
      //Password Contol 
      if (loginPass.equals(password)) { 
       Log.w("İf","............................................."); 
       intent = new Intent(this, HomePage.class); 
       startActivity(intent); 
      } else { 
       Log.w("come", "else"); 
      } 
      break; 
     case R.id.uyeBtn: 
      intent = new Intent(this, Register.class); 
      startActivity(intent); 
      break; 
     }}} 
+0

を助けるこれを試してみてください、あなたの 'UserName'と' Pass'インデックスは0と1であることを確認していますか? –

+0

** parola **はパスワードです..? –

+0

はい私は再びインデックスの場所が正しいことを確認しました@MichaelShrestha –

答えて

0

あなたは

String[] columns ={"field_1", "field_2"} 
Cursor pCursor = db.query(db_table, columns, "username_field=?", new String[] { USERNAME }, null, null, null); 
+0

「username_field = @Michael Shrestha –

+0

Username_field ??どこuのurのユーザー名を保存する??その列の名前 –

0

このアプローチを試みることができるそれはあなたの

/////DatabaseHelper.java 


    public class DatabaseHelper extends SQLiteOpenHelper{ 
     private static final int db_version=2; 
     private static final String db_Name="SosyalMedyaDB.db"; 
     private static final String db_table="Kisi"; 

     private static final int Index_UserName=0; 
     private static final int Index_UserPassword=1; 

    //Db Create 

    private static final String DATABASE_CREATE = "CREATE TABLE \"Kisi\" (
    `isim` TEXT NOT NULL, `parola` TEXT, `email` TEXT, `cinsiyet` TEXT, `tarih` 
    TEXT, `resim` INTEGER, " + 
      "`url` TEXT)"; 
    SQLiteDatabase db; 
    public DatabaseHelper(Context context) 
    { 
     super(context,db_Name,null,db_version); 
    } 
    @Override 
    public void onCreate(SQLiteDatabase db) { 
     db.execSQL(DATABASE_CREATE); 
     this.db=db; 
     } 
    public String searchPass(String usName) 
    { 
     db=this.getReadableDatabase(); 
     String query="select * from "+db_table; 
     Cursor cursor=db.rawQuery(query,null); 
     String a,b; 
     b="not found"; 
     if(cursor.moveToFirst()) 
     { 
      do { 
       a = cursor.getString(Index_UserName); 
       b=cursor.getString(Index_UserPassword); 
       if (a.equals(usName)) 
       { 
        b = cursor.getString(Index_UserPassword); 
        db.close(); 
      break; 
      }} 
       while (cursor.moveToNext()); 
      } 
      return b; 
     } 
    @Override 
     public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) 
    { 
     db.execSQL("DROP TABLE IF EXISTS "+db_table); 
     this.onCreate(db); 
     } 
    } 


    //////Login.java 

    public class Login extends AppCompatActivity implements View.OnClickListener{ 
     EditText name,pass; 
     ArrayList<Kisi> uyeler; 
     String loginIsim, loginPass; 
     Intent intent; 
     DatabaseHelper dbHelper=new DatabaseHelper(this); 
     Button btnLogin; 
     String userName, userPassword; 
     @Override 
      protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.activity_login); 

     name = (EditText) findViewById(R.id.loginName); 
     pass = (EditText) findViewById(R.id.password); 
    btnLogin=(Button)findviewbyid(R.id.girisBtn); 
    btnLogin.setOnClickListener(this); 
     loginIsim = name.getText().toString(); 
     loginPass = pass.getText().toString(); 
      } 
     public void onClick(View v) { 
     switch (v.getId()) { 
      case R.id.girisBtn: 
       Log.w(".............. ",""); 
       String password = dbHelper.searchPass(loginIsim); 
       Log.w("string password ","................"); 
     //Password Contol 
       if (loginPass.equals(password)) { 
        Log.w("İf","............................................."); 
        intent = new Intent(this, HomePage.class); 
        startActivity(intent); 
       } else { 
        Log.w("come", "else"); 
       } 
       break; 
      case R.id.uyeBtn: 
       intent = new Intent(this, Register.class); 
       startActivity(intent); 
       break; 
      }}} 
+0

@Sagar Patel –

+0

エラーメッセージは送信されません。@Sagar Patel –

+0

07-03 14:22:53.267 30569- 30569/com.tatlicilar.sosyalmedyauygulamasi I/ViewRootImpl:ViewRootのタッチイベント:ACTION_UP 07-03 14:22:53.270 30569-30569/com.tatlicilar.sosyalmedyauygulamasi W/stringパスワード:........... ..... 07-03 14:22:53.270 30569-30569/com.tatlicilar.sosyalmedyauygulamasi W/come:else 07-03 14:22:53.273 30569-30569/com.tatlicilar.sosyalmedyauygulamasi W/stringパスワード:................ 07-03 14:22:53.273 30569-30569/com.tatlicilar.sosyalmedyauygulamasi W/come:else @Sagar Patel –

関連する問題