From 7e38b4a6aea6642f118c9f488296ac2c7c19bbda Mon Sep 17 00:00:00 2001 From: regev avraham Date: Fri, 11 May 2018 22:02:48 +0300 Subject: [PATCH 1/2] fix #8 issue. The problem was that after inserting a new planet the cursor updated instead of creating new cursor, then on the swapCursor function, the old cursor (which is also the new cursor) was closed and then when we tried to read the content out of the new cursor (also the old cursor) we got an exception since the cursor was closed --- .../com/example/android/mygarden/ui/PlantListAdapter.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/example/android/mygarden/ui/PlantListAdapter.java b/app/src/main/java/com/example/android/mygarden/ui/PlantListAdapter.java index 484a909f..fed2c495 100644 --- a/app/src/main/java/com/example/android/mygarden/ui/PlantListAdapter.java +++ b/app/src/main/java/com/example/android/mygarden/ui/PlantListAdapter.java @@ -81,8 +81,11 @@ public void onBindViewHolder(PlantViewHolder holder, int position) { holder.plantImageView.setTag(plantId); } - public void swapCursor(Cursor newCursor) { - if (mCursor != null) { + public void swapCursor(Cursor newCursor) + { + Log.d(TAG, "swapCursor: cursor: "+newCursor.isClosed()); + if (mCursor != null && mCursor != newCursor) + { mCursor.close(); } mCursor = newCursor; From 443694694487f18253a793c2a50952de90226f44 Mon Sep 17 00:00:00 2001 From: Regev Avraham Date: Fri, 11 May 2018 22:24:04 +0300 Subject: [PATCH 2/2] remove the log statment --- .../java/com/example/android/mygarden/ui/PlantListAdapter.java | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/com/example/android/mygarden/ui/PlantListAdapter.java b/app/src/main/java/com/example/android/mygarden/ui/PlantListAdapter.java index fed2c495..4d73ee58 100644 --- a/app/src/main/java/com/example/android/mygarden/ui/PlantListAdapter.java +++ b/app/src/main/java/com/example/android/mygarden/ui/PlantListAdapter.java @@ -83,7 +83,6 @@ public void onBindViewHolder(PlantViewHolder holder, int position) { public void swapCursor(Cursor newCursor) { - Log.d(TAG, "swapCursor: cursor: "+newCursor.isClosed()); if (mCursor != null && mCursor != newCursor) { mCursor.close();