From 099d9e26f3284539415e30c23fc1293c77bcdff2 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 24 Jun 2026 23:11:51 +0000 Subject: [PATCH] Fix race condition NullPointerException in EmpowerPlantActivity Fixes ANDROID-EH Add null check in onResume() database observer callback before calling textCartItemCount.setText(). This prevents a NullPointerException when the callback fires before onCreateOptionsMenu() has initialized the textCartItemCount view. The race condition occurred because: - onResume() subscribes to a database observer that updates textCartItemCount - onCreateOptionsMenu() initializes textCartItemCount - onCreateOptionsMenu() can be invoked after onResume(), creating a window where the callback fires with a null textCartItemCount reference --- .../vu/android/empowerplant/EmpowerPlantActivity.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/example/vu/android/empowerplant/EmpowerPlantActivity.java b/app/src/main/java/com/example/vu/android/empowerplant/EmpowerPlantActivity.java index 973ce14..6e3956f 100644 --- a/app/src/main/java/com/example/vu/android/empowerplant/EmpowerPlantActivity.java +++ b/app/src/main/java/com/example/vu/android/empowerplant/EmpowerPlantActivity.java @@ -140,9 +140,11 @@ protected void onResume() { .observeSelectedCount() .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) - .subscribe(count -> - textCartItemCount.setText(String.valueOf(count)) - ) + .subscribe(count -> { + if (textCartItemCount != null) { + textCartItemCount.setText(String.valueOf(count)); + } + }) ); }