2

这是我的项目

在这里,我想在我的数据库中插入一些东西。我也将此链接 用作参考,但徒劳无功。

但这是我的错误日志。

05-04 16:53:20.272: E/AndroidRuntime(18378): FATAL EXCEPTION: main
05-04 16:53:20.272: E/AndroidRuntime(18378): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.crews.databaseproto.activity/com.crews.databaseproto.activity.DatabaseProtoActivity}: java.lang.IllegalStateException: database not open
05-04 16:53:20.272: E/AndroidRuntime(18378):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
05-04 16:53:20.272: E/AndroidRuntime(18378):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
05-04 16:53:20.272: E/AndroidRuntime(18378):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)  
05-04 16:53:20.272: E/AndroidRuntime(18378):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
05-04 16:53:20.272: E/AndroidRuntime(18378):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-04 16:53:20.272: E/AndroidRuntime(18378):    at android.os.Looper.loop(Looper.java:130)
05-04 16:53:20.272: E/AndroidRuntime(18378):    at android.app.ActivityThread.main(ActivityThread.java:3687)
05-04 16:53:20.272: E/AndroidRuntime(18378):    at java.lang.reflect.Method.invokeNative(Native Method)
05-04 16:53:20.272: E/AndroidRuntime(18378):    at java.lang.reflect.Method.invoke(Method.java:507)
05-04 16:53:20.272: E/AndroidRuntime(18378):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
05-04 16:53:20.272: E/AndroidRuntime(18378):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
05-04 16:53:20.272: E/AndroidRuntime(18378):    at dalvik.system.NativeStart.main(Native Method)
05-04 16:53:20.272: E/AndroidRuntime(18378): Caused by: java.lang.IllegalStateException: database not open
05-04 16:53:20.272: E/AndroidRuntime(18378):    at android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:555)
05-04 16:53:20.272: E/AndroidRuntime(18378):    at com.crews.databaseproto.activity.DataBaseHelper.insertData(DataBaseHelper.java:153)
05-04 16:53:20.272: E/AndroidRuntime(18378):    at com.crews.databaseproto.activity.DatabaseProtoActivity.onCreate(DatabaseProtoActivity.java:37)
05-04 16:53:20.272: E/AndroidRuntime(18378):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-04 16:53:20.272: E/AndroidRuntime(18378):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
05-04 16:53:20.272: E/AndroidRuntime(18378):    ... 11 more

提前致谢。抱歉链接错误

4

3 回答 3

1

打开数据库如下

 SqliteDatabase db=myDbHelper.getWritableDatabase();
 ContentValues cv=new ContentValues();
 cv.put(COLUMN_NAME,10);
 cv.put(COLUMN_NAME,"Kaushik");
 cv.put(COLUMN_NAME,"dhor sala");
 cv.put(COLUMN_NAME,22.332322332);
 cv.put(COLUMN_NAME,88.2323232);
 float row id=db.insert(TABLE_NAME,null,cv);
于 2012-05-04T12:08:46.133 回答
1
public synchronized SQLiteDatabase getWritableDatabase()

无需覆盖此功能。只需使用内置的。

还,

checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);

myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READWRITE);

更改您打开要写入的数据库的模式。

于 2012-05-04T13:13:26.550 回答
0

数据已插入,但由于 DeptId 是主键,因此在表 Dept 中插入重复数据时出错。

 05-05 00:01:09.783: E/Database(1011):  at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1562)
于 2012-05-04T11:32:47.283 回答