gpt4 book ai didi

Android SQLite onUpgrade = 强制关闭

转载 作者:行者123 更新时间:2023-11-30 04:48:18 29 4
gpt4 key购买 nike

情况是这样的。我正在升级我的数据库,添加一个列。升级似乎很顺利。我可以看到添加了新列,但问题是当我的应用程序从旧版本升级到带有新数据库的新版本时,我强制关闭了。访问新列时似乎发生强制关闭。但是,如果我进行全新安装,则不会强制关闭并且应用程序会按预期工作。

我的 upUpgrade 看起来是这样的:

  @Override   public void onUpgrade(SQLiteDatabase notes_db, int oldVersion, int newVersion) {    if (oldVersion == 29) {
notes_db.execSQL("ALTER TABLE Notes ADD COLUMN Priority text");
notes_db.execSQL("ALTER TABLE Todo ADD COLUMN Priority text");
notes_db.execSQL("ALTER TABLE Todo_keys ADD COLUMN Priority text"); } else {
notes_db.execSQL("DROP TABLE IF EXISTS " + NOTES_TABLE);
notes_db.execSQL("DROP TABLE IF EXISTS " + TODO_TABLE);
notes_db.execSQL("DROP TABLE IF EXISTS " + TODO_KEYS_TABLE);
onCreate(notes_db); } }

如有任何想法,我们将不胜感激。

这是我认为它失败的地方......

11-23 14:37:06.210: DEBUG/AndroidRuntime(1647): Shutting down VM
11-23 14:37:06.210: WARN/dalvikvm(1647): threadid=1: thread exiting with uncaught exception (group=0x4001d7e8)
11-23 14:37:06.210: ERROR/AndroidRuntime(1647): FATAL EXCEPTION: main
11-23 14:37:06.210: ERROR/AndroidRuntime(1647): java.lang.NullPointerException
11-23 14:37:06.210: ERROR/AndroidRuntime(1647): at com.flufflydelusions.app.extensive_notes_donate.Notes$TaskSimpleCursorAdapter.getView(Notes.java:1065)
11-23 14:37:06.210: ERROR/AndroidRuntime(1647): at android.widget.AbsListView.obtainView(AbsListView.java:1315)
11-23 14:37:06.210: ERROR/AndroidRuntime(1647): at android.widget.ListView.measureHeightOfChildren(ListView.java:1198)
11-23 14:37:06.210: ERROR/AndroidRuntime(1647): at android.widget.ListView.onMeasure(ListView.java:1109)
11-23 14:37:06.210: ERROR/AndroidRuntime(1647): at android.view.View.measure(View.java:8173)
11-23 14:37:06.210: ERROR/AndroidRuntime(1647): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
11-23 14:37:06.210: ERROR/AndroidRuntime(1647): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1012)
11-23 14:37:06.210: ERROR/AndroidRuntime(1647): at android.widget.LinearLayout.measureVertical(LinearLayout.java:381)
11-23 14:37:06.210: ERROR/AndroidRuntime(1647): at android.widget.LinearLayout.onMeasure(LinearLayout.java:304)
11-23 14:37:06.210: ERROR/AndroidRuntime(1647): at android.view.View.measure(View.java:8173)
11-23 14:37:06.210: ERROR/AndroidRuntime(1647): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3132)
11-23 14:37:06.210: ERROR/AndroidRuntime(1647): at android.widget.FrameLayout.onMeasure(FrameLayout.java:245)
11-23 14:37:06.210: ERROR/AndroidRuntime(1647): at android.view.View.measure(View.java:8173)
11-23 14:37:06.210: ERROR/AndroidRuntime(1647): at android.widget.LinearLayout.measureVertical(LinearLayout.java:526)

第 1065 行是 catch 语句,priority1 是我添加的新列..

String priority1 = c.getString(c.getColumnIndex(databaseHelper.DB_COLUMN_PRIORITY));

        if (priority1.equals("Low")) {
try {
String low_pref = preferences.getString("low_priority_color", "Default");
if (!low_pref.equals("Default")){
priority_text.setBackgroundColor(Integer.parseInt(low_pref, 16)+0xFF000000);
priority_text.setVisibility(View.VISIBLE);
} else {
priority_text.setBackgroundColor(0xFFFFe640);
priority_text.setVisibility(View.VISIBLE);
}} catch (Exception e) {
errorText = e.getMessage();
themeError();
}
}

最佳答案

已修复。新列有空值

关于Android SQLite onUpgrade = 强制关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4260243/

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