Good day. The isRegister method works incorrectly, the result: One of the activations, when calling the isRegister method, throws them out of the application, but must switch (isRegister) through one of the activations and go into it. I wonder if the isRegister method is wrong, how to arrange it correctly, to check an empty table or not. Here is the code:
class DBHelper extends SQLiteOpenHelper { private DBHelper dbHelper; DBHelper(Context context) { super(context, "myDB", null, 1); } @Override public void onCreate(SQLiteDatabase db) { db.execSQL("create table Users (" + "id integer primary key autoincrement," + "name text," + "birthday date," + "city text" + ");"); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {} void addAccount(String name, String city, String editTextDateParam) { ContentValues cv = new ContentValues(); SQLiteDatabase db = dbHelper.getWritableDatabase(); cv.put("name", name); cv.put("birthday", editTextDateParam); cv.put("city", city); db.insert("Users", null, cv); dbHelper.close(); } int isRegister() { SQLiteDatabase db = dbHelper.getWritableDatabase(); Cursor c = db.query("Users", null, null, null, null, null, null); if (!c.moveToFirst()) { c.close(); dbHelper.close(); return 0; } else { c.close(); dbHelper.close(); return 1; } } }