在android中创建sqlite数据库时强制关闭

时间:2013-04-28 08:14:40

标签: android database sqlite forceclose

这里我有一个错误,当我尝试在android中创建sqlite时,应用程序将在启动应用程序期间强制执行。当我删除用于创建数据库的代码时,可以运行应用程序。所以我想,我的数据库助手类可能有问题。任何人都知道我的错误是什么?有人可以帮忙。谢谢你......

DBAdapater.java

    SQLiteDatabase mDb;
DBHelper mDbHelper;

public DBAdapter(Context context){
    //this.mCtx = context;
    //mDbHelper = new DBHelper(mCtx);
    mDbHelper = new DBHelper(context);
    mDb = mDbHelper.getWritableDatabase();
}

public void close(){
    mDbHelper.close();
    }

DBHelper.java

    public DBHelper(Context context) {
    super(context, "medical", null, 1);
    }

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL("CREATE TABLE  (" +
            "Staff_ID INTEGER PRIMARY KEY AUTOINCREMENT, " +
            "Staff_Name TEXT NOT NULL," +
            "Password TEXT NOT NULL," +
            "Staff_Acid TEXT NOT NULL," +
            "Ward_Name TEXT NOT NULL);");
    }

@Override
public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
    db.execSQL("DROP TABLE IF EXISTS members");
    onCreate(db);
    }

myactivity class

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
//code for create sqlite
dbAdapter = new DBAdapter(PatientMedicalRecordActivity.this);

}

0 个答案:

没有答案