1

我是 Android 新手,我正在制作我的第一个 Android 应用程序。在那,我正在创建一个数据库。在这个应用程序中,第一次启动应用程序时,我要求用户输入新密码并在 mynewscreen 中确认密码。下次用户启动应用程序时,它会要求用户输入他现有的密码并检查数据库中的密码。

但是在代码中,我附近有错误checkDataBase()

我的代码:

SQLiteDatabase sampleDB =  this.openOrCreateDatabase(SAMPLE_DB_NAME, MODE_PRIVATE, null);
          Cursor c = sampleDB.rawQuery("SELECT Password FROM " +
                  "password" +
                  " where Username = 'clicklock'", null);

任何人都可以帮助游标 c 语句中的错误是什么?

 public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        logm("App started");

        String chreturn=Make_db();
        Toast.makeText(getApplicationContext(),chreturn,Toast.LENGTH_LONG).show();

        checkDataBase();       

}

 public String Make_db()
    {
   String errormsg = "";
   SQLiteDatabase sampleDB =  this.openOrCreateDatabase(SAMPLE_DB_NAME, MODE_PRIVATE, null);
   try {
        sampleDB.execSQL("CREATE TABLE IF NOT EXISTS " +
                PASSWORD +
                " (Username VARCHAR, Password VARCHAR);");

        sampleDB.execSQL("CREATE TABLE IF NOT EXISTS " +            PHOTO + " (photoname VARCHAR, photopath VARCHAR,id INTEGER PRIMARY KEY);");
           msg ="DatabaseCreated";
       } catch (SQLiteException se ) {
        Log.e(getClass().getSimpleName(), "Could not create or Open the database");
        msg ="Not Done Error With Database";
       }
 return msg;

   }
   public  String checkDataBase() {

    try
    {
        SQLiteDatabase sampleDB =  this.openOrCreateDatabase(SAMPLE_DB_NAME, MODE_PRIVATE, null);
      Cursor c = sampleDB.rawQuery("SELECT Password FROM " +
              "password" +
              " where Username = 'clicklock'", null);

      String password_db = c.getString(c.getColumnIndex("password"));
        if(password_db=="")
        {

            Intent i = new Intent(CameraLaunch.this, MyNewScreen.class);                
            startActivity(i);               
        }
        else if(password_db=="123123")
        {               
            Intent i = new Intent(CameraLaunch.this, MyNewScreen.class);                
            startActivity(i);       
        }


      return "working";
    }
     catch (SQLiteException se ) {
         Log.e(getClass().getSimpleName(), "Could not create or Open the database");
         Make_db();
         return "Could not create or Open the database";
     }        
}

4

0 回答 0