Skip to content Skip to sidebar Skip to footer

Nullpointerexception Openorcreatedatabase Android

i m gettin a NullPointerException in my EhActivity class while opening a database public class EHActivity extends Activity { ArrayListques= new ArrayList

Solution 1:

try not sending null.. openOrCreateDatabase has another method for this..

db2=openOrCreateDatabase("interview.db", MODE_PRIVATE);

or

openDatabase("interview.db", MODE_PRIVATE, SQLiteDatabase.CREATE_IF_NECESSARY)

Solution 2:

publicclassDatabase_creat {
    privatestaticfinalStringDATABASE_NAME="interview.db";
    publicstaticfinalStringDATABASE_TABLE_CATEGORY="category";
    publicstaticfinalStringDATABASE_TABLE_TODO_LIST="todo_list";
    privatestaticfinalintDATABASE_VERSION=1;
    public ArrayList<ModelToDO> list;


    private DataBaseHelper mDbhelper;
    private SQLiteDatabase mDb;

    Context mContext;
    privatestaticfinalStringDATABASE_CREATE_CATEGORY="create table category(id integer primary key autoincrement , "
            + "category text not null);";
    privatestaticfinalStringDATABASE_CREATE_TODO_LIST="create table todo_list(id integer primary key autoincrement , "
            + "title text not null,description text not null,category text not null, due_date Date not null,alarm_time text ,alarm_set text,priority text,parform Boolean);";

    privatestaticclassDataBaseHelperextendsSQLiteOpenHelper {

        DataBaseHelper(Context context) {
            super(context, DATABASE_NAME, null, DATABASE_VERSION);
            // TODO Auto-generated constructor stub
        }

        @OverridepublicvoidonCreate(SQLiteDatabase db) {
            // TODO Auto-generated method stub
            db.execSQL(DATABASE_CREATE_CATEGORY);
            db.execSQL(DATABASE_CREATE_TODO_LIST);
        }

        //Delete All todo_list Table infopublicvoidonUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            // TODO Auto-generated method stub
            db.execSQL("DROP TABLE IF EXISTS submit");
            onCreate(db);
        }
    }

    publicDatabase_creat(Context context) {
        this.mContext = context;
    }

    public Database_creat Open()throws SQLException {
        mDbhelper = newDataBaseHelper(mContext);
        mDb = mDbhelper.getWritableDatabase();
        returnthis;

    }

    publicvoidclose() {
        mDbhelper.close();
    }

    //Add new Category namepubliclonginsertinfo(String cate) {
        ContentValuescon=newContentValues();
        con.put("category", cate);
        return mDb.insert(DATABASE_TABLE_CATEGORY, null, con);
    }


}

this one create database in used query

Solution 3:

HI Shubh Try The Following Code..

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>


db2=openOrCreateDatabase("sdcard/yourappfolder/interview.db", MODE_PRIVATE, null);

Post a Comment for "Nullpointerexception Openorcreatedatabase Android"