2017-07-08 99 views
-1

我正在寫一個簡單的登錄應用程序,我遇到了麻煩登錄控制到我的數據庫。我添加了assest教室數據庫,但它仍然沒有看到數據庫。當我點擊login.xml頁面上的「Giris」按鈕後,我收到此錯誤:E/SQLiteLog:(1)沒有這樣的表:KisilerTable D/AndroidRuntime:關閉虛擬機 E/AndroidRuntime:致命異常:主要 進程:com.tatlicilar.sosyalmedyauygulamasi,PID:5397 android.database.sqlite.SQLiteException:沒有這樣的表:KisilerTable(代碼1):,編譯時:SELECT * FROM KisilerTable WHERE isim =?Android SQLite:沒有這樣的表

///登錄活動

public class Login extends AppCompatActivity implements 

    View.OnClickListener{ 
     EditText name,pass; 
     ArrayList<Kisi> uyeler; 
     String loginIsim, loginPass; 
     Intent intent; 
     DBAdapter dbHelper=new DBAdapter(this); 
     Button btnLogin; 

@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); 

} 
public void onClick(View v) { 
    switch (v.getId()) { 
     case R.id.girisBtn: 
      loginIsim = name.getText().toString(); 
      loginPass = pass.getText().toString(); 
      Log.w(".............. ",""); 
      String password = dbHelper.getSinlgeEntry(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; 
    }} 

}

//DBAdapter.java

public class Login extends AppCompatActivity implements 
     View.OnClickListener{ 
     EditText name,pass; 
     ArrayList<Kisi> uyeler; 
    String loginIsim, loginPass; 
    Intent intent; 
    DBAdapter dbHelper=new DBAdapter(this); 
    Button btnLogin; 

@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); 


} 
public void onClick(View v) { 
    switch (v.getId()) { 
     case R.id.girisBtn: 
      loginIsim = name.getText().toString(); 
      loginPass = pass.getText().toString(); 
      Log.w(".............. ",""); 
      String password = dbHelper.getSinlgeEntry(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; 
    }} 

}

+1

後正確DBAdapter.java類 – FAT

回答

0

類DBAdapter.java內容是錯誤的代碼。是登錄Activity.change

0

您的表格KisilerTable沒有正確創建在SQLite數據庫。您正在以錯誤的方式創建DBAdapter實例。您應該在Activity生命週期method內創建DBAdapter實例。

更新如下:

public class Login extends AppCompatActivity implements View.OnClickListener { 

    ....... 
    ............. 

    DBAdapter dbHelper; 

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

     dbHelper = new DBAdapter(this); 
    } 

    ....... 
    .............. 
} 

希望它幫助〜