0

我尝试在 android 上测试数据库。我想在 sumsung GALAXY TAB 中运行我的项目。所以,我设置 AVD 是 Galaxy Nexus ,RAM = 512,VM Heap = 64,SD Card = 1024 MiB 。我创建的 android 项目名称是 SQLiteDatabase 。当我在 AVD 上运行 SQLiteDatabase 时,它​​会显示此错误。

不幸的是,SQLite 数据库已经停止。

我不知道为什么我不能运行 SQLiteDatabase 项目,这是来自 logcat 的错误。

01-09 04:17:27.347: I/Process(6519): Sending signal. PID: 6519 SIG:9
     01-09 04:17:33.517: W/Trace(6848): Unexpected value from nativeGetEnabledTags: 0
     01-09 04:17:33.517: W/Trace(6848): Unexpected value from nativeGetEnabledTags: 0
     01-09 04:17:33.562: W/Trace(6848): Unexpected value from nativeGetEnabledTags: 0
     01-09 04:17:33.562: W/Trace(6848): Unexpected value from nativeGetEnabledTags: 0
     01-09 04:17:34.917: D/dalvikvm(6848): GC_CONCURRENT freed 75K, 7% free 2744K/2948K, paused 12ms+6ms, total 122ms
     01-09 04:17:34.917: D/dalvikvm(6848): WAIT_FOR_CONCURRENT_GC blocked 71ms
     01-09 04:17:34.937: I/dalvikvm-heap(6848): Grow heap (frag case) to 3.868MB for 1127536-byte allocation
     01-09 04:17:35.027: D/dalvikvm(6848): GC_FOR_ALLOC freed 2K, 6% free 3843K/4052K, paused 84ms, total 85ms
     01-09 04:17:35.227: D/dalvikvm(6848): GC_CONCURRENT freed <1K, 6% free 3847K/4052K, paused 10ms+4ms, total 199ms
     01-09 04:17:35.347: E/SQLiteLog(6848): (1) near "tabletool": syntax error
     01-09 04:17:35.359: D/AndroidRuntime(6848): Shutting down VM
     01-09 04:17:35.359: W/dalvikvm(6848): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
     01-09 04:17:35.417: E/AndroidRuntime(6848): FATAL EXCEPTION: main
     01-09 04:17:35.417: E/AndroidRuntime(6848): java.lang.RuntimeException: Unable to start activity
 ComponentInfo{com.example.sqlitedatabase/com.example.sqlitedatabase.MainActivity}:
 android.database.sqlite.SQLiteException: near "tabletool": syntax
 error (code 1): , while compiling: create tabletool(idinteger primary
 key autoincrement ,nametext ,amountnumericunitunit
     01-09 04:17:35.417: E/AndroidRuntime(6848):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
     01-09 04:17:35.417: E/AndroidRuntime(6848):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
     01-09 04:17:35.417: E/AndroidRuntime(6848):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
     01-09 04:17:35.417: E/AndroidRuntime(6848):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
     01-09 04:17:35.417: E/AndroidRuntime(6848):     at android.os.Handler.dispatchMessage(Handler.java:99)
     01-09 04:17:35.417: E/AndroidRuntime(6848):     at android.os.Looper.loop(Looper.java:137)
     01-09 04:17:35.417: E/AndroidRuntime(6848):     at android.app.ActivityThread.main(ActivityThread.java:5039)
     01-09 04:17:35.417: E/AndroidRuntime(6848):     at java.lang.reflect.Method.invokeNative(Native Method)
     01-09 04:17:35.417: E/AndroidRuntime(6848):     at java.lang.reflect.Method.invoke(Method.java:511)
     01-09 04:17:35.417: E/AndroidRuntime(6848):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
     01-09 04:17:35.417: E/AndroidRuntime(6848):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
     01-09 04:17:35.417: E/AndroidRuntime(6848):     at dalvik.system.NativeStart.main(Native Method)
     01-09 04:17:35.417: E/AndroidRuntime(6848): Caused by: android.database.sqlite.SQLiteException: near "tabletool": syntax
 error (code 1): , while compiling: create tabletool(idinteger primary
 key autoincrement ,nametext ,amountnumericunitunit
     01-09 04:17:35.417: E/AndroidRuntime(6848):     at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native
 Method)
     01-09 04:17:35.417: E/AndroidRuntime(6848):     at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
     01-09 04:17:35.417: E/AndroidRuntime(6848):     at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
     01-09 04:17:35.417: E/AndroidRuntime(6848):     at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
     01-09 04:17:35.417: E/AndroidRuntime(6848):     at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
     01-09 04:17:35.417: E/AndroidRuntime(6848):     at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
     01-09 04:17:35.417: E/AndroidRuntime(6848):     at android.database.sqlite.SQLiteDatabase.executeSql(SQLiteDatabase.java:1663)
     01-09 04:17:35.417: E/AndroidRuntime(6848):     at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1594)
     01-09 04:17:35.417: E/AndroidRuntime(6848):     at com.example.sqlitedatabase.SimpleSQLiteHelper.onCreate(SimpleSQLiteHelper.java:43)
     01-09 04:17:35.417: E/AndroidRuntime(6848):     at android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:252)
     01-09 04:17:35.417: E/AndroidRuntime(6848):     at android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:164)
     01-09 04:17:35.417: E/AndroidRuntime(6848):     at com.example.sqlitedatabase.ToolDataSource.open(ToolDataSource.java:28)
     01-09 04:17:35.417: E/AndroidRuntime(6848):     at com.example.sqlitedatabase.MainActivity.onCreate(MainActivity.java:36)
     01-09 04:17:35.417: E/AndroidRuntime(6848):     at android.app.Activity.performCreate(Activity.java:5104)
     01-09 04:17:35.417: E/AndroidRuntime(6848):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
     01-09 04:17:35.417: E/AndroidRuntime(6848):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
     01-09 04:17:35.417: E/AndroidRuntime(6848):     ... 11 more
4

2 回答 2

2
ComponentInfo{com.example.sqlitedatabase/com.example.sqlitedatabase.MainActivity}: android.database.sqlite.SQLiteException: near "tabletool": syntax error (code 1): , while compiling: create tabletool(idinteger primary key autoincrement ,nametext ,amountnumericunitunit 01-09 04:17:35.417: E/AndroidRuntime(6848): at 

没有可用的代码,但根据上面的异常堆栈,您在创建表“tabletool”时似乎有一些语法错误

确保创建表语法有效(空格、冒号等,在需要的地方有)。

于 2013-01-09T04:32:26.483 回答
1

嘿嘿在日志里发现你的表查询有误。

像这样更改此查询

create tabletool(id integer primary key autoincrement ,name text

我只能在日志中看到您忘记维护空格的两个参数。在参数和数据类型之间放置空格并尝试一下。它对你有用。

检查你写的查询,应该是idintegernametextid integername text

于 2013-01-09T04:38:24.240 回答