NullPointerException openOrCreateDatabase Android

前端 未结 3 1827
别跟我提以往
别跟我提以往 2021-01-24 00:13

i m gettin a NullPointerException in my EhActivity class while opening a database

 public class EHActivity extends Activity {
ArrayListques= new Ar         


        
相关标签:
3条回答
  • 2021-01-24 00:37

    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)
    
    0 讨论(0)
  • 2021-01-24 00:57

    HI Shubh Try The Following Code..

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    
    
    db2=openOrCreateDatabase("sdcard/yourappfolder/interview.db", MODE_PRIVATE, null);
    
    0 讨论(0)
  • 2021-01-24 00:59
    public class Database_creat {
        private static final String DATABASE_NAME = "interview.db";
        public static final String DATABASE_TABLE_CATEGORY = "category";
        public static final String DATABASE_TABLE_TODO_LIST = "todo_list";
        private static final int DATABASE_VERSION = 1;
        public ArrayList<ModelToDO> list;
    
    
        private DataBaseHelper mDbhelper;
        private SQLiteDatabase mDb;
    
        Context mContext;
        private static final String DATABASE_CREATE_CATEGORY = "create table category(id integer primary key autoincrement , "
                + "category text not null);";
        private static final String DATABASE_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);";
    
        private static class DataBaseHelper extends SQLiteOpenHelper {
    
            DataBaseHelper(Context context) {
                super(context, DATABASE_NAME, null, DATABASE_VERSION);
                // TODO Auto-generated constructor stub
            }
    
            @Override
            public void onCreate(SQLiteDatabase db) {
                // TODO Auto-generated method stub
                db.execSQL(DATABASE_CREATE_CATEGORY);
                db.execSQL(DATABASE_CREATE_TODO_LIST);
            }
    
            //Delete All todo_list Table info
            public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
                // TODO Auto-generated method stub
                db.execSQL("DROP TABLE IF EXISTS submit");
                onCreate(db);
            }
        }
    
        public Database_creat(Context context) {
            this.mContext = context;
        }
    
        public Database_creat Open() throws SQLException {
            mDbhelper = new DataBaseHelper(mContext);
            mDb = mDbhelper.getWritableDatabase();
            return this;
    
        }
    
        public void close() {
            mDbhelper.close();
        }
    
        //Add new Category name
        public long insertinfo(String cate) {
            ContentValues con = new ContentValues();
            con.put("category", cate);
            return mDb.insert(DATABASE_TABLE_CATEGORY, null, con);
        }
    
    
    }
    

    this one create database in used query

    0 讨论(0)
提交回复
热议问题