Getting a null pointer exception at squlite query.
Following is my code snippet
String myPath = DB_PATH + DATABASE_NAME;
SQLiteDatabase checkDB = null;
checkDB = SQLiteDatabase.openDatabase(myPath, null,SQLiteDatabase.OPEN_READONLY);
if(checkDB != null){
Cursor cursor = database.rawQuery("SELECT Id, UserName FROM Login Where status="+ 1, null);
if(cursor != null ) {
if (cursor.moveToFirst()){
String UserName = cursor.getString(cursor.getColumnIndex("UserName"));
String mail_id = cursor.getString(cursor.getColumnIndex("status"));
Intent intent = new Intent(MainActivity.this, UserAccount.class);
/*Sending some arguments*/
Bundle bundle = new Bundle();
bundle.putString("UserName",UserName);
bundle.putString("Id", mail_id);
intent.putExtras(bundle);
startActivity(intent);
When I debugged the code, I have got a path value in checkDB variable but cursor value is null. So that I have getting null pointer exception at the line
Cursor cursor = database.rawQuery("SELECT Id, UserName FROM Login Where status="+ 1, null);
I couldn't find the source of reason, Please help me...
Cursor cursor = database.rawQuery("SELECT Id, UserName FROM Login Where status=1", null);does it works?