private static final String DB_NAME = "Examples_06_06.db";
private static class DatabaseHelper extends SQLiteOpenHelper{
/* 构造函数-创建一个数据库 */
DatabaseHelper(Context context){
super(context, DB_NAME, null, DB_VERSION);
}
为什么我在DB_NAME = "Examples_06_06.db"里把Examples_06_06.db改成其它的名称后,安装apk到模拟器上会出现一个强制关闭的程序的异常呢?查看数据据库文件夹数据库也创建成功了,但是Activity无法运行。
求解!!!
下面是LogCat里的信息05-09 06:46:52.630: ERROR/Zygote(32): setreuid() failed. errno: 1705-09 06:46:52.630: ERROR/BatteryService(42): usbOnlinePath not found
05-09 06:46:52.630: ERROR/BatteryService(42): batteryVoltagePath not found
05-09 06:46:52.630: ERROR/BatteryService(42): batteryTemperaturePath not found05-09 06:46:52.630: ERROR/SurfaceFlinger(42): Couldn't open /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake
05-09 06:46:52.630: ERROR/SurfaceFlinger(42): Couldn'topen /sys/power/wait_for_fb_sleep or /sys/power/wait_for_fb_wake
05-09 06:47:23.169: WARN/zipro(69):
Unable to openzip '/data/local/bootanimation.zip': No such file or directory
05-09 06:47:23.169: WARN/zipro(69):
Unable to open zip '/system/media/bootanimation.zip': No such file or directory05-09 06:46:52.630: WARN/Zygote(32):
Preloaded drawable resource #0x1080002 (res/drawable-mdpi/arrow_down_float.png) that varies with configuration!!05-09 06:46:52.630: WARN/Zygote(32):
Preloaded drawable resource #0x1080009 (res/drawable/btn_radio.xml) that varies with configuration!!
05-09 06:47:28.609: ERROR/EventHub(42):
could not get driver version for /dev/input/mouse0, Not a typewriter
05-09 06:47:28.609: ERROR/EventHub(42):
could not get driver version for /dev/input/mice, Not a typewriter05-09 06:47:28.879: ERROR/System(42): Failure starting core service
05-09 06:47:28.879: ERROR/System(42): java.lang.SecurityException
05-09 06:47:28.879: ERROR/System(42):
at android.os.BinderProxy.transact(Native Method)
05-09 06:47:28.879: ERROR/System(42):
at android.os.ServiceManagerProxy.addService(ServiceManagerNative.java:146)
05-09 06:47:28.879: ERROR/System(42):
at android.os.ServiceManager.addService(ServiceManager.java:72)
05-09 06:47:28.879: ERROR/System(42):
at com.android.server.ServerThread.run(SystemServer.java:184)05-09 06:47:29.800: ERROR/SoundPool(42): error loading /system/media/audio/ui/Effect_Tick.ogg
05-09 06:47:29.809: ERROR/SoundPool(42): error loading /system/media/audio/ui/KeypressStandard.ogg
05-09 06:47:29.809: ERROR/SoundPool(42): error loading /system/media/audio/ui/KeypressSpacebar.ogg
05-09 06:47:29.809: ERROR/SoundPool(42): error loading /system/media/audio/ui/KeypressDelete.ogg
05-09 06:47:29.809: ERROR/SoundPool(42): error loading /system/media/audio/ui/KeypressReturn.ogg05-09 06:47:31.849: ERROR/ThrottleService(42):
Could not open GPS configuration file /etc/gps.conf05-09 06:47:32.779: ERROR/logwrapper(130):
executing /system/bin/tc failed: No such file or directory05-09 06:47:41.821: ERROR/HierarchicalStateMachine(42):
TetherMaster - unhandledMessage: msg.what=305-09 06:48:05.206: ERROR/Database(277): Failure 1 (near "TABLEtable1": syntax error) on 0x216d70 when preparing 'CREATE TABLEtable1(_idINTEGER PRIMARY KEY,num INTEGER,data TEXT)'.05-09 06:48:05.276: ERROR/AndroidRuntime(277): FATAL EXCEPTION: main
05-09 06:48:05.276: ERROR/AndroidRuntime(277): java.lang.RuntimeException: Unable to start activity ComponentInfo{cjz.sqlite1/cjz.sqlite1.sqlite}: android.database.sqlite.SQLiteException: near "TABLEtable1": syntax error: CREATE TABLEtable1(_idINTEGER PRIMARY KEY,num INTEGER,data TEXT)
05-09 06:48:05.276: ERROR/AndroidRuntime(277): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-09 06:48:05.276: ERROR/AndroidRuntime(277): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-09 06:48:05.276: ERROR/AndroidRuntime(277): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-09 06:48:05.276: ERROR/AndroidRuntime(277): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-09 06:48:05.276: ERROR/AndroidRuntime(277): at android.os.Handler.dispatchMessage(Handler.java:99)
05-09 06:48:05.276: ERROR/AndroidRuntime(277): at android.os.Looper.loop(Looper.java:123)
05-09 06:48:05.276: ERROR/AndroidRuntime(277): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-09 06:48:05.276: ERROR/AndroidRuntime(277): at java.lang.reflect.Method.invokeNative(Native Method)
05-09 06:48:05.276: ERROR/AndroidRuntime(277): at java.lang.reflect.Method.invoke(Method.java:521)
05-09 06:48:05.276: ERROR/AndroidRuntime(277): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-09 06:48:05.276: ERROR/AndroidRuntime(277): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-09 06:48:05.276: ERROR/AndroidRuntime(277): at dalvik.system.NativeStart.main(Native Method)
05-09 06:48:05.276: ERROR/AndroidRuntime(277): Caused by: android.database.sqlite.SQLiteException: near "TABLEtable1": syntax error: CREATE TABLEtable1(_idINTEGER PRIMARY KEY,num INTEGER,data TEXT)
05-09 06:48:05.276: ERROR/AndroidRuntime(277): at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method)
05-09 06:48:05.276: ERROR/AndroidRuntime(277): at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1727)
05-09 06:48:05.276: ERROR/AndroidRuntime(277): at cjz.sqlite1.db.MyDataBaseAdapter$DatabaseHelper.onCreate(MyDataBaseAdapter.java:65)
05-09 06:48:05.276: ERROR/AndroidRuntime(277): at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:106)
05-09 06:48:05.276: ERROR/AndroidRuntime(277): at cjz.sqlite1.db.MyDataBaseAdapter.open(MyDataBaseAdapter.java:86)
05-09 06:48:05.276: ERROR/AndroidRuntime(277): at cjz.sqlite1.sqlite.onCreate(sqlite.java:55)
05-09 06:48:05.276: ERROR/AndroidRuntime(277): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-09 06:48:05.276: ERROR/AndroidRuntime(277): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-09 06:48:05.276: ERROR/AndroidRuntime(277): ... 11 more
这句话就是程序终止的原因
实现 SQLiteOpenHelper的派生类时 要实现回调onCreate()方法, 第一次调用时 回调该方法 创建表格onCreate(.....){
db.execSQL(CREATE .....);
}
最常见的SQ语法错误,主要原因是创建表的SQ语句的格式不对,“TABLEtable1”改为“TABLE table1”,即在中间加个空格。