Good morning stackoverflow lovers :) i wrote my Sqlite class , but there is an error "Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.database.sqlite.SQLiteDatabase.execSQL(java.lang.String)' on a null object reference"
I know it is because (db) is null , but i already gave it a value of getWritableDatabase() and here is my code
public class sqlite extends SQLiteOpenHelper{
public SQLiteDatabase db;
public sqlite(Context context , String db_name , int db_version){
super(context, db_name, null, db_version, null);
this.db=db();
}
public SQLiteDatabase db(){
if(this.db==null){try{this.db=getWritableDatabase();}catch(Exception e){this.db=getReadableDatabase();}}
return this.db;
}
public void test(table){
db.execSQL("CREATE TABLE IF NOT EXISTS "+table); ***//ERROR db is null , why????***
}
}