Android SQLite onUpgrade =强制关闭

时间:2010-11-23 19:53:24

标签: android sqlite

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

我的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();
                }                   
            }   

1 个答案:

答案 0 :(得分:1)

固定。新列具有空值