From b30b045e25c2c563539dc852e848a59c7879487d Mon Sep 17 00:00:00 2001 From: Neel Parekh Date: Mon, 5 Oct 2009 14:56:48 -0700 Subject: [PATCH] Fix NPE being thrown when starting the AttachImage activity. Bug: 2164613 --- src/com/android/contacts/AttachImage.java | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/com/android/contacts/AttachImage.java b/src/com/android/contacts/AttachImage.java index c8b6322..6970842 100644 --- a/src/com/android/contacts/AttachImage.java +++ b/src/com/android/contacts/AttachImage.java @@ -59,7 +59,7 @@ public class AttachImage extends Activity { } - private Long[] rawContactIds; + private Long[] mRawContactIds; private ContentResolver mContentResolver; @@ -68,7 +68,7 @@ public class AttachImage extends Activity { super.onCreate(icicle); if (icicle != null) { - rawContactIds = toClassArray(icicle.getLongArray(RAW_CONTACT_URIS_KEY)); + mRawContactIds = toClassArray(icicle.getLongArray(RAW_CONTACT_URIS_KEY)); } else { Intent intent = new Intent(Intent.ACTION_GET_CONTENT); intent.setType(Contacts.CONTENT_ITEM_TYPE); @@ -82,12 +82,15 @@ public class AttachImage extends Activity { protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); - if (rawContactIds != null && rawContactIds.length != 0) { - outState.putLongArray(RAW_CONTACT_URIS_KEY, toPrimativeArray(rawContactIds)); + if (mRawContactIds != null && mRawContactIds.length != 0) { + outState.putLongArray(RAW_CONTACT_URIS_KEY, toPrimativeArray(mRawContactIds)); } } private static long[] toPrimativeArray(Long[] in) { + if (in == null) { + return null; + } long[] out = new long[in.length]; for (int i = 0; i < in.length; i++) { out[i] = in[i]; @@ -96,6 +99,9 @@ public class AttachImage extends Activity { } private static Long[] toClassArray(long[] in) { + if (in == null) { + return null; + } Long[] out = new Long[in.length]; for (int i = 0; i < in.length; i++) { out[i] = in[i]; @@ -130,15 +136,15 @@ public class AttachImage extends Activity { final long contactId = ContentUris.parseId(result.getData()); final ArrayList rawContactIdsList = ContactsUtils.queryForAllRawContactIds( mContentResolver, contactId); - rawContactIds = new Long[rawContactIdsList.size()]; - rawContactIds = rawContactIdsList.toArray(rawContactIds); + mRawContactIds = new Long[rawContactIdsList.size()]; + mRawContactIds = rawContactIdsList.toArray(mRawContactIds); - if (rawContactIds == null || rawContactIdsList.isEmpty()) { + if (mRawContactIds == null || rawContactIdsList.isEmpty()) { Toast.makeText(this, R.string.contactSavedErrorToast, Toast.LENGTH_LONG).show(); } } else if (requestCode == REQUEST_CROP_PHOTO) { final Bundle extras = result.getExtras(); - if (extras != null) { + if (extras != null && mRawContactIds != null) { Bitmap photo = extras.getParcelable("data"); if (photo != null) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); @@ -149,7 +155,7 @@ public class AttachImage extends Activity { imageValues.put(RawContacts.Data.IS_SUPER_PRIMARY, 1); // attach the photo to every raw contact - for (Long rawContactId : rawContactIds) { + for (Long rawContactId : mRawContactIds) { // exchange and google only allow one image, so do an update rather than insert boolean shouldUpdate = false; -- 2.11.0