gpt4 book ai didi

java - Android SQLite 游标错误

转载 作者:行者123 更新时间:2023-12-01 15:30:28 26 4
gpt4 key购买 nike

此代码出现运行时错误。我的错误是什么?

String myPath = DB_PATH + DB_NAME;
myDataBase = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY);
Cursor cur = myDataBase.rawQuery("SELECT * FROM personel" , null);
cur.moveToFirst();
cur.close();
myDataBase.close();

这是我的日志猫:

这是我的日志猫:

03-06 14:35:14.821: E/AndroidRuntime(11995): FATAL EXCEPTION: main
03-06 14:35:14.821: E/AndroidRuntime(11995): java.lang.RuntimeException: Unable to start activity ComponentInfo{Dic.proj.pkg/Dic.proj.pkg.DictionaryActivity}: android.database.sqlite.SQLiteException: no such table: personel: , while compiling: Select * from personel
03-06 14:35:14.821: E/AndroidRuntime(11995): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
03-06 14:35:14.821: E/AndroidRuntime(11995): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
03-06 14:35:14.821: E/AndroidRuntime(11995): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
03-06 14:35:14.821: E/AndroidRuntime(11995): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
03-06 14:35:14.821: E/AndroidRuntime(11995): at android.os.Handler.dispatchMessage(Handler.java:99)
03-06 14:35:14.821: E/AndroidRuntime(11995): at android.os.Looper.loop(Looper.java:123)
03-06 14:35:14.821: E/AndroidRuntime(11995): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-06 14:35:14.821: E/AndroidRuntime(11995): at java.lang.reflect.Method.invokeNative(Native Method)
03-06 14:35:14.821: E/AndroidRuntime(11995): at java.lang.reflect.Method.invoke(Method.java:507)
03-06 14:35:14.821: E/AndroidRuntime(11995): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-06 14:35:14.821: E/AndroidRuntime(11995): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-06 14:35:14.821: E/AndroidRuntime(11995): at dalvik.system.NativeStart.main(Native Method)
03-06 14:35:14.821: E/AndroidRuntime(11995): Caused by: android.database.sqlite.SQLiteException: no such table: personel: , while compiling: Select * from personel
03-06 14:35:14.821: E/AndroidRuntime(11995): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
03-06 14:35:14.821: E/AndroidRuntime(11995): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:92)
03-06 14:35:14.821: E/AndroidRuntime(11995): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:65)
03-06 14:35:14.821: E/AndroidRuntime(11995): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:83)
03-06 14:35:14.821: E/AndroidRuntime(11995): at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:49)
03-06 14:35:14.821: E/AndroidRuntime(11995): at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:42)
03-06 14:35:14.821: E/AndroidRuntime(11995): at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1356)
03-06 14:35:14.821: E/AndroidRuntime(11995): at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1324)
03-06 14:35:14.821: E/AndroidRuntime(11995): at Dic.proj.pkg.DataBaseHelper.getCount(DataBaseHelper.java:126)
03-06 14:35:14.821: E/AndroidRuntime(11995): at Dic.proj.pkg.DictionaryActivity.onCreate(DictionaryActivity.java:44)
03-06 14:35:14.821: E/AndroidRuntime(11995): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-06 14:35:14.821: E/AndroidRuntime(11995): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)

最佳答案

您最近可能包含了“personel”表并且没有升级数据库版本,或者您可能更改了“personel”的定义,因此请尝试在此处增加DataBase-Version:

public DatabaseHelper(Context context) 
{
super(context, dbName, null,Increment the value here);
}

关于java - Android SQLite 游标错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9580909/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com