Sqlite数据库创建问题

时间:2013-04-07 17:34:09

标签: android sqlite

我试图在sqlite中创建一个数据库但是没有创建它。

文件资源管理器中没有显示数据库文件夹。

任何人都可以在下面给出的代码中发现任何错误

public DatabaseHelper(Context context) {

    super(context, databasename, null, databaseversion);
    Log.d("DatabaseHelper", "Reached Database helper");
    mContext = context;
}

@Override
public void onCreate(SQLiteDatabase db) {
    String CREATE_MASTER_TABLE = "CREATE TABLE " + table_reminder_master
            + "(" + MASTER_ID + " INTEGER PRIMARY KEY ," + MASTER_TITLE
            + " TEXT," + MASTER_CONTACT_ID + " INTEGER," + MASTER_EMAIL_ID
            + " INTEGER," + MASTER_TYPE_ID + " INTEGER," + ")";
    db.execSQL(CREATE_MASTER_TABLE);
    Log.d("Table Create", "The table is created");
    Toast.makeText(mContext, "Created", Toast.LENGTH_LONG).show();

    String CREATE_CONTACT_TABLE = "CREATE TABLE " + table_contactDetails
            + "(" + CONTACT_ID + " INTEGER PRIMARY KEY ," + CONTACT_NAME
            + " TEXT," + ")";
    db.execSQL(CREATE_CONTACT_TABLE);
}

调用类

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    db = new DatabaseHelper(this); // instantiation of database helper
    initializerMethod();
    reminder=new Reminder_Master();
    contact=new Contact_Details();
    Log.d("Main Acitivity", "Message");
    btnSave.setOnClickListener(saveHandler);
    }

任何帮助表示赞赏

2 个答案:

答案 0 :(得分:1)

您在两个创建查询中都出现语法错误:

+ " INTEGER," + MASTER_TYPE_ID + " INTEGER," + ")";

+ " TEXT," + ")";

,之前的)不应该在那里。

你应该检查logcat,因为这样的错误会在抛出并记录异常时结束。

答案 1 :(得分:0)

仅创建DatabaseHelper是不够的。您必须致电getReadableDatabase()getWriteableDatabase()。请务必在后台线程上执行此操作,因为您不希望在主应用程序线程上执行磁盘I / O.