diff --git a/OpenVehicleApp/src/com/openvehicles/OVMS/ui/utils/Database.java b/OpenVehicleApp/src/com/openvehicles/OVMS/ui/utils/Database.java index 480cf50b..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,13 +529,18 @@ 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)); contentValues.put("nTitle", notificationData.Title); contentValues.put("nMessage", notificationData.Message); + if(db == null) + throw new NullPointerException( "Open database first." ); db.insert("Notification", null, contentValues); }