From 8bf595a5b99087ffce832dcd014cfce103915d38 Mon Sep 17 00:00:00 2001 From: anhr Date: Mon, 13 Apr 2015 06:53:54 +0700 Subject: [PATCH 1/2] bug of update of database to version 5 --- OpenVehicleApp/src/com/openvehicles/OVMS/ui/utils/Database.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/OpenVehicleApp/src/com/openvehicles/OVMS/ui/utils/Database.java b/OpenVehicleApp/src/com/openvehicles/OVMS/ui/utils/Database.java index 480cf50b..37f4ea22 100644 --- a/OpenVehicleApp/src/com/openvehicles/OVMS/ui/utils/Database.java +++ b/OpenVehicleApp/src/com/openvehicles/OVMS/ui/utils/Database.java @@ -536,6 +536,8 @@ private void addNotificationInt(NotificationData notificationData) { contentValues.put("nTimestamp", isoDateTime.format(notificationData.Timestamp)); contentValues.put("nTitle", notificationData.Title); contentValues.put("nMessage", notificationData.Message); + if(db == null) + throw new NullPointerException( "Open database first." ); db.insert("Notification", null, contentValues); } From 73f839905e8c06b6a9652aed0f603947815bb34f Mon Sep 17 00:00:00 2001 From: anhr Date: Tue, 14 Apr 2015 10:53:31 +0700 Subject: [PATCH 2/2] bug of update of database to version 5 I have excluded db==null exception during updating database to version 5. Before db==null, because database not yet opened during updating database to version 5. See call stack: Thread [<1> main] (Suspended (breakpoint at line 540 in Database)) Database.addNotificationInt(NotificationData) line: 540 Database.onUpgrade(SQLiteDatabase, int, int) line: 172 Database(SQLiteOpenHelper).getDatabaseLocked(boolean) line: 257 Database(SQLiteOpenHelper).getWritableDatabase() line: 164 Database.open() line: 37 Database.getlatlngdetail(int, int) line: 285 MainActivity.updatelocation() line: 423 MainActivity.onCreate(Bundle) line: 65 MainActivity(Activity).performCreate(Bundle) line: 5231 Instrumentation.callActivityOnCreate(Activity, Bundle) line: 1087 ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2159 ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 2245 ActivityThread.access$800(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 135 ActivityThread$H.handleMessage(Message) line: 1196 ActivityThread$H(Handler).dispatchMessage(Message) line: 102 Looper.loop() line: 136 ActivityThread.main(String[]) line: 5017 Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method] Method.invoke(Object, Object...) line: 515 ZygoteInit$MethodAndArgsCaller.run() line: 779 ZygoteInit.main(String[]) line: 595 NativeStart.main(String[]) line: not available [native method] Instead I am updating another instance of database, opened in the Database(SQLiteOpenHelper).getDatabaseLocked(boolean) function. --- .../src/com/openvehicles/OVMS/ui/utils/Database.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/OpenVehicleApp/src/com/openvehicles/OVMS/ui/utils/Database.java b/OpenVehicleApp/src/com/openvehicles/OVMS/ui/utils/Database.java index 37f4ea22..13e34681 100644 --- a/OpenVehicleApp/src/com/openvehicles/OVMS/ui/utils/Database.java +++ b/OpenVehicleApp/src/com/openvehicles/OVMS/ui/utils/Database.java @@ -169,7 +169,7 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // copy to db: for (int i=0; i < notifications.size(); i++) { - addNotificationInt(notifications.get(i)); + addNotificationInt(notifications.get(i), db); } Log.d(TAG, String.format("Added %d notifications to table.", notifications.size())); @@ -529,8 +529,11 @@ public void addNotification(NotificationData notificationData) { open(); addNotificationInt(notificationData); } - private void addNotificationInt(NotificationData notificationData) { + addNotificationInt(notificationData, db); + } + + private void addNotificationInt(NotificationData notificationData, SQLiteDatabase db) { ContentValues contentValues = new ContentValues(); contentValues.put("nType", notificationData.Type); contentValues.put("nTimestamp", isoDateTime.format(notificationData.Timestamp));