From 95d19347d6f6f20658f29286c7e3ce81e97d9b97 Mon Sep 17 00:00:00 2001 From: Marcos Marado Date: Thu, 14 Apr 2016 15:41:42 +0100 Subject: avoid NPE Change-Id: I8a2d74c8c305112fcbb76d56b126d15a6015de8b --- src/com/android/launcher3/LauncherProvider.java | 38 ++++++++++++++----------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java index 05184cf0e..bdb5c5bf1 100644 --- a/src/com/android/launcher3/LauncherProvider.java +++ b/src/com/android/launcher3/LauncherProvider.java @@ -547,23 +547,29 @@ public class LauncherProvider extends ContentProvider { // Database was just created, so wipe any previous widgets if (mAppWidgetHost != null) { - mAppWidgetHost.deleteHost(); - - /** - * Send notification that we've deleted the {@link AppWidgetHost}, - * probably as part of the initial database creation. The receiver may - * want to re-call {@link AppWidgetHost#startListening()} to ensure - * callbacks are correctly set. - */ - new MainThreadExecutor().execute(new Runnable() { - - @Override - public void run() { - if (mListener != null) { - mListener.onAppWidgetHostReset(); + try { + mAppWidgetHost.deleteHost(); + /** + * Send notification that we've deleted the {@link AppWidgetHost}, + * probably as part of the initial database creation. The receiver may + * want to re-call {@link AppWidgetHost#startListening()} to ensure + * callbacks are correctly set. + */ + new MainThreadExecutor().execute(new Runnable() { + + @Override + public void run() { + if (mListener != null) { + mListener.onAppWidgetHostReset(); + } } - } - }); + }); + } catch (NullPointerException ex) { + // nothing to do here. Why did this pass the null check? I don't know. but this fixes it. + // (avoids: Caused by: java.lang.NullPointerException: Attempt to invoke interface method + // 'void com.android.internal.appwidget.IAppWidgetService.deleteHost(java.lang.String, int)' + // on a null object reference + } } // Fresh and clean launcher DB. -- cgit v1.2.3