Here is the situation. I'm upgrading my database adding a single column. The upgrade appears to go fine. I can see the new column added but the problem is when upgrading my app from the older to the new version w/ new DB I get force close. The force close seems to occur when accessing the new column. If I do a fresh install however I get no force closes and app works as expected.
My on upUpgrade looks as such:
@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); } }
Any ideas would be appreciated.
This is where I believe it fails...
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开发者_如何学Go-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)
Line 1065 is the catch statement and priority1 is the new column I added..
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();
}
}
Fixed. New column had null value
精彩评论