andrroid couldn't open database for writing(will try read-only)
06-27 10:11:02.591: I/Database(2514): sqlite returned: error code = 1, msg = near "fault_item_num": syntax error 06-27 10:11:02.591: E/Database(2514): Failure 1 (near "fault_item_num": syntax error) on 0x2d7448 when preparing 'create table IF NOT EXISTS fault_item_table(_id integer primary key autoincrement ,fault_diector_name varchar(50)fault_item_num varchar(50),fault_item_name varchar(50),fault_item_first varchar(255),fault_item_second varchar(255),fault_item_third varchar(255));'. 06-27 10:11:02.611: E/SQLiteOpenHelper(2514): Couldn't open managedb.db for writing (will try read-only): 06-27 10:11:02.611: E/SQLiteOpenHelper(2514): android.database.sqlite.SQLiteException: near "fault_item_num": syntax error: create table IF NOT EXISTS fault_item_table(_id integer primary key autoincrement ,fault_diector_name varchar(50)fault_item_num varchar(50),fault_item_name varchar(50),fault_item_first varchar(255),fault_item_second varchar(255),fault_item_third varchar(255)); 06-27 10:11:02.611: E/SQLiteOpenHelper(2514): at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method) 06-27 10:11:02.611: E/SQLiteOpenHelper(2514): at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1763) 06-27 10:11:02.611: E/SQLiteOpenHelper(2514): at org.monsterlab.database.DbHelper.onCreate(DbHelper.java:54) 06-27 10:11:02.611: E/SQLiteOpenHelper(2514): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:126) 06-27 10:11:02.611: E/SQLiteOpenHelper(2514): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:187) 06-27 10:11:02.611: E/SQLiteOpenHelper(2514): at org.monsterlab.database.FaultDiectoryDbManager.<init>(FaultDiectoryDbManager.java:25) 06-27 10:11:02.611: E/SQLiteOpenHelper(2514): at org.monsterlab.main_activity.FaultDiectoryActivity.onCreate(FaultDiectoryActivity.java:43) 06-27 10:11:02.611: E/SQLiteOpenHelper(2514): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 06-27 10:11:02.611: E/SQLiteOpenHelper(2514): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 06-27 10:11:02.611: E/SQLiteOpenHelper(2514): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 06-27 10:11:02.611: E/SQLiteOpenHelper(2514): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 06-27 10:11:02.611: E/SQLiteOpenHelper(2514): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 06-27 10:11:02.611: E/SQLiteOpenHelper(2514): at android.os.Handler.dispatchMessage(Handler.java:99) 06-27 10:11:02.611: E/SQLiteOpenHelper(2514): at android.os.Looper.loop(Looper.java:123) 06-27 10:11:02.611: E/SQLiteOpenHelper(2514): at android.app.ActivityThread.main(ActivityThread.java:3683) 06-27 10:11:02.611: E/SQLiteOpenHelper(2514): at java.lang.reflect.Method.invokeNative(Native Method) 06-27 10:11:02.611: E/SQLiteOpenHelper(2514): at java.lang.reflect.Method.invoke(Method.java:507) 06-27 10:11:02.611: E/SQLiteOpenHelper(2514): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 06-27 10:11:02.611: E/SQLiteOpenHelper(2514): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 06-27 10:11:02.611: E/SQLiteOpenHelper(2514): at dalvik.system.NativeStart.main(Native Method)
android cann't upgrade read-only database from version 0 to 1
06-27 10:11:02.661: E/AndroidRuntime(2514): FATAL EXCEPTION: main 06-27 10:11:02.661: E/AndroidRuntime(2514): java.lang.RuntimeException: Unable to start activity ComponentInfo{org.monsterlab.main_activity/org.monsterlab.main_activity.FaultDiectoryActivity}: android.database.sqlite.SQLiteException: Can't upgrade read-only database from version 0 to 1: /data/data/org.monsterlab.main_activity/databases/managedb.db 06-27 10:11:02.661: E/AndroidRuntime(2514): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647) 06-27 10:11:02.661: E/AndroidRuntime(2514): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663) 06-27 10:11:02.661: E/AndroidRuntime(2514): at android.app.ActivityThread.access$1500(ActivityThread.java:117) 06-27 10:11:02.661: E/AndroidRuntime(2514): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931) 06-27 10:11:02.661: E/AndroidRuntime(2514): at android.os.Handler.dispatchMessage(Handler.java:99) 06-27 10:11:02.661: E/AndroidRuntime(2514): at android.os.Looper.loop(Looper.java:123) 06-27 10:11:02.661: E/AndroidRuntime(2514): at android.app.ActivityThread.main(ActivityThread.java:3683) 06-27 10:11:02.661: E/AndroidRuntime(2514): at java.lang.reflect.Method.invokeNative(Native Method) 06-27 10:11:02.661: E/AndroidRuntime(2514): at java.lang.reflect.Method.invoke(Method.java:507) 06-27 10:11:02.661: E/AndroidRuntime(2514): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 06-27 10:11:02.661: E/AndroidRuntime(2514): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 06-27 10:11:02.661: E/AndroidRuntime(2514): at dalvik.system.NativeStart.main(Native Method) 06-27 10:11:02.661: E/AndroidRuntime(2514): Caused by: android.database.sqlite.SQLiteException: Can't upgrade read-only database from version 0 to 1: /data/data/org.monsterlab.main_activity/databases/managedb.db 06-27 10:11:02.661: E/AndroidRuntime(2514): at android.database.sqlite.SQLiteOpenHelper.getReadableDatabase(SQLiteOpenHelper.java:199) 06-27 10:11:02.661: E/AndroidRuntime(2514): at org.monsterlab.database.FaultDiectoryDbManager.<init>(FaultDiectoryDbManager.java:25) 06-27 10:11:02.661: E/AndroidRuntime(2514): at org.monsterlab.main_activity.FaultDiectoryActivity.onCreate(FaultDiectoryActivity.java:43) 06-27 10:11:02.661: E/AndroidRuntime(2514): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) 06-27 10:11:02.661: E/AndroidRuntime(2514): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611) 06-27 10:11:02.661: E/AndroidRuntime(2514): ... 11 more
嗯,以上是两个exception,但是却是同时出现的,我被这个问题困扰了1个小时才发现是我脑残了。。。。。不过google上搜索出的答案都是在*上的,并且他们有这个问题,可惜都没明确解决,我出现此问题是因为,我修改了sqlite的表,所以删除原数据库,再次运行,数据库自动创建了,表没有,后来我发现,是我建表的sql语句错误,少加了一个逗号,而*上那些在模拟器上运行正常而在真机上运行出现这个错误,可能是因为他们在模拟器上的的数据库和表本身是由正确的sql语句创建的,但是可能他们后期修改了sql语句,比如建表语句,但是数据库和表本身存在,而不会出错,可是在真机上安装应用后运行,需要创建数据库和表,于是出现此错误,因为表没创建,只有一个原始的数据库,这点我试验过,有兴趣的朋友也可以试试,若是有更准确的答案,求告知。