Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用android的方法查询崩溃_Android_Sqlite - Fatal编程技术网

用android的方法查询崩溃

用android的方法查询崩溃,android,sqlite,Android,Sqlite,我正在尝试验证在我的db android中是否有用户注册。我有一个创建db的类,它有一个验证用户是否已注册的方法: public boolean isRegistered(String username, String password) { boolean in = false; Cursor cursor = db.query(TABLE_NAME_USER, new String[] {USERNAME,PASSWORD},

我正在尝试验证在我的db android中是否有用户注册。我有一个创建db的类,它有一个验证用户是否已注册的方法:

    public boolean isRegistered(String username, String password) {
          boolean in = false;
          Cursor cursor = db.query(TABLE_NAME_USER, new String[] {USERNAME,PASSWORD},
            USERNAME + " = '" + username + "' AND " + PASSWORD + "= '" + password+"'",
            null, null, null, null);

          if(cursor.moveToFirst())
                  in=true;
          if(!cursor.isClosed())
                  cursor.close();
   return in;
   }

运行此方法时,应用程序崩溃。为什么?您能帮我吗?

您可以将简单的查询传递到数据库,并从中获取用户计数。像这样

 public static SQLiteDatabase Objdatabase;

 SQLiteStatement stmtSelectRec=Objdatabase.compileStatement("Select count(0) from table where username='abc' and password='123'");  

 int countnumber=(int)stmtSelectRec.simpleQueryForLong();

 if(countnumber)>0?True:false.

埃格尔。我在手机中看不到数据库,但当我添加新用户时,将新用户放入数据库的功能不会崩溃…但此功能会崩溃!