0

我试图在 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);
    }

任何帮助表示赞赏

4

2 回答 2

1

您在两个创建查询中都遇到了语法错误:

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

+ " TEXT," + ")";

,之前)不应该存在。

您应该检查过 logcat,因为此类错误以抛出和记录异常结束。

于 2013-04-07T17:38:24.577 回答
0

仅仅创建DatabaseHelper是不够的。你必须打电话getReadableDatabase()getWriteableDatabase()。确保在后台线程上执行此操作,因为您不想在主应用程序线程上执行磁盘 I/O。

于 2013-04-07T17:51:18.853 回答