0

我一直在尝试让一个 android 应用程序连接到位于 localhost 上的数据库,但到目前为止我一直没有运气。我的程序过去可以启动,我可以在文本字段中输入文本,但是一旦我做了一些更改,它现在甚至无法启动。我查看了 LogCat,但我不知道问题可能是什么。我在这方面有点新,认为那里的任何人都可以帮助我吗?

这是来自 LogCat 的错误日志:

08-08 20:31:35.367: E/AndroidRuntime(605): FATAL EXCEPTION: main
08-08 20:31:35.367: E/AndroidRuntime(605): java.lang.RuntimeException: Unable to start activity     ComponentInfo{com.example.databasetester/com.example.databasetester.DashboardActivity}: android.database.sqlite.SQLiteException: no such table: users: , while compiling: SELECT  * FROM users
08-08 20:31:35.367: E/AndroidRuntime(605):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2049)
08-08 20:31:35.367: E/AndroidRuntime(605):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2083)
08-08 20:31:35.367: E/AndroidRuntime(605):  at android.app.ActivityThread.access$600(ActivityThread.java:134)
08-08 20:31:35.367: E/AndroidRuntime(605):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1233)
08-08 20:31:35.367: E/AndroidRuntime(605):  at android.os.Handler.dispatchMessage(Handler.java:99)
08-08 20:31:35.367: E/AndroidRuntime(605):  at android.os.Looper.loop(Looper.java:137)
08-08 20:31:35.367: E/AndroidRuntime(605):  at android.app.ActivityThread.main(ActivityThread.java:4697)
08-08 20:31:35.367: E/AndroidRuntime(605):  at java.lang.reflect.Method.invokeNative(Native Method)
08-08 20:31:35.367: E/AndroidRuntime(605):  at java.lang.reflect.Method.invoke(Method.java:511)
08-08 20:31:35.367: E/AndroidRuntime(605):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
08-08 20:31:35.367: E/AndroidRuntime(605):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
08-08 20:31:35.367: E/AndroidRuntime(605):  at dalvik.system.NativeStart.main(Native Method)
08-08 20:31:35.367: E/AndroidRuntime(605): Caused by: android.database.sqlite.SQLiteException: no such table: users: , while compiling: SELECT  * FROM users
08-08 20:31:35.367: E/AndroidRuntime(605):  at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
08-08 20:31:35.367: E/AndroidRuntime(605):  at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:68)
08-08 20:31:35.367: E/AndroidRuntime(605):  at android.database.sqlite.SQLiteProgram.compileSql(SQLiteProgram.java:143)
08-08 20:31:35.367: E/AndroidRuntime(605):  at android.database.sqlite.SQLiteProgram.compileAndbindAllArgs(SQLiteProgram.java:361)
08-08 20:31:35.367: E/AndroidRuntime(605):  at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:127)
08-08 20:31:35.367: E/AndroidRuntime(605):  at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:94)
08-08 20:31:35.367: E/AndroidRuntime(605):  at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:53)
08-08 20:31:35.367: E/AndroidRuntime(605):  at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:47)
08-08 20:31:35.367: E/AndroidRuntime(605):  at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1671)
08-08 20:31:35.367: E/AndroidRuntime(605):  at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1645)
08-08 20:31:35.367: E/AndroidRuntime(605):  at library.DatabaseHandler.getRowCount(DatabaseHandler.java:103)
08-08 20:31:35.367: E/AndroidRuntime(605):  at library.UserFunctions.isUserLoggedIn(UserFunctions.java:71)
08-08 20:31:35.367: E/AndroidRuntime(605):  at com.example.databasetester.DashboardActivity.onCreate(DashboardActivity.java:24)
08-08 20:31:35.367: E/AndroidRuntime(605):  at android.app.Activity.performCreate(Activity.java:4539)
08-08 20:31:35.367: E/AndroidRuntime(605):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
08-08 20:31:35.367: E/AndroidRuntime(605):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2013)
08-08 20:31:35.367: E/AndroidRuntime(605):  ... 11 more

我还应该补充一点,我的数据库中有一个名为“users”的表。如果你们需要我展示我的一些代码(我相信你们会的),我会非常乐意。

4

1 回答 1

0

这是错误:

08-08 20:31:35.367: E/AndroidRuntime(605): FATAL EXCEPTION: main
08-08 20:31:35.367: E/AndroidRuntime(605): java.lang.RuntimeException: 
  Unable to start activity
  ComponentInfo{com.example.databasetester/com.example.databasetester.DashboardActivity}:
    android.database.sqlite.SQLiteException: no such table: users: , 
  while compiling: SELECT  * FROM users

建议:

1)确保你一个表“用户”(你说你有,但请仔细检查)

... 和 ...

2)确保您正确指定了数据库文件:

* SQLite 异常:没有这样的表错误

如果您没有正确指定数据库文件名,我相信它会退回到创建一个空数据库。这通常是“找不到表”的原因。检查您的路径和数据库文件名。

于 2012-08-08T21:16:34.900 回答