From 5cc4d7c6a916117efbf21873c3338835697dd2c6 Mon Sep 17 00:00:00 2001 From: Joe Steele Date: Sat, 5 Apr 2014 23:43:53 -0400 Subject: [PATCH] Avoid NPE in MessageOpenPgpView.updateLayout() E/AndroidRuntime(24914): FATAL EXCEPTION: main E/AndroidRuntime(24914): Process: com.fsck.k9, PID: 24914 E/AndroidRuntime(24914): java.lang.NullPointerException E/AndroidRuntime(24914): at org.openintents.openpgp.util.OpenPgpServiceConnection.(OpenPgpServiceConnection.java:35) E/AndroidRuntime(24914): at com.fsck.k9.view.MessageOpenPgpView.updateLayout(MessageOpenPgpView.java:115) E/AndroidRuntime(24914): at com.fsck.k9.view.SingleMessageView.setMessage(SingleMessageView.java:623) E/AndroidRuntime(24914): at com.fsck.k9.fragment.MessageViewFragment$Listener$2.run(MessageViewFragment.java:602) E/AndroidRuntime(24914): at android.os.Handler.handleCallback(Handler.java:733) E/AndroidRuntime(24914): at android.os.Handler.dispatchMessage(Handler.java:95) E/AndroidRuntime(24914): at android.os.Looper.loop(Looper.java:136) E/AndroidRuntime(24914): at android.app.ActivityThread.main(ActivityThread.java:5081) E/AndroidRuntime(24914): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime(24914): at java.lang.reflect.Method.invoke(Method.java:515) E/AndroidRuntime(24914): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791) E/AndroidRuntime(24914): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607) E/AndroidRuntime(24914): at dalvik.system.NativeStart.main(Native Method) --- src/com/fsck/k9/view/MessageOpenPgpView.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/com/fsck/k9/view/MessageOpenPgpView.java b/src/com/fsck/k9/view/MessageOpenPgpView.java index 758cb5c28..1c65e4707 100644 --- a/src/com/fsck/k9/view/MessageOpenPgpView.java +++ b/src/com/fsck/k9/view/MessageOpenPgpView.java @@ -17,6 +17,7 @@ import android.content.Context; import android.content.Intent; import android.content.IntentSender.SendIntentException; import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentActivity; import android.util.AttributeSet; import android.util.Log; import android.view.View; @@ -110,8 +111,12 @@ public class MessageOpenPgpView extends LinearLayout { return; } + FragmentActivity activity = mFragment.getActivity(); + if (activity == null) { + return; + } // bind to service - mOpenPgpServiceConnection = new OpenPgpServiceConnection(mFragment.getActivity(), + mOpenPgpServiceConnection = new OpenPgpServiceConnection(activity, mOpenPgpProvider); mOpenPgpServiceConnection.bindToService();