Skip to content

Fix NullPointerException in EmpowerPlantActivity cart count observer - #263

Open
cursor[bot] wants to merge 1 commit into
mainfrom
nullpointerexception-attempt-to-o3ivjf
Open

Fix NullPointerException in EmpowerPlantActivity cart count observer#263
cursor[bot] wants to merge 1 commit into
mainfrom
nullpointerexception-attempt-to-o3ivjf

Conversation

@cursor

@cursor cursor Bot commented Aug 21, 2026

Copy link
Copy Markdown

Summary

Fixes a NullPointerException that occurs when the cart count observer fires before the options menu is inflated in EmpowerPlantActivity.

Problem

The cart item count LiveData observer in onResume() was calling setText() on textCartItemCount without checking if it was null. Since onResume() runs before onCreateOptionsMenu() in the Activity lifecycle, textCartItemCount would be null when the observer first fires, causing the app to crash on startup.

Solution

Added a null check before calling setText() on textCartItemCount in the cart count observer. This prevents the crash while still allowing the cart badge to update once the menu is inflated.

Testing

  • Launch the Android app and open EmpowerPlantActivity
  • Ensure the cart has items
  • Activity no longer crashes on startup
  • Cart badge updates correctly once the menu is created

Fixes ANDROID-HZ

Open in Web Open in Cursor 

Add null check for textCartItemCount before calling setText() in the
cart count observer. The observer fires in onResume before the options
menu is inflated in onCreateOptionsMenu, causing textCartItemCount to
be null when the observer tries to update the cart badge.

Fixes [ANDROID-HZ](https://demo.sentry.io/issues/7562174288/)
@ndmanvar
ndmanvar marked this pull request as ready for review August 21, 2026 10:12
@ndmanvar
ndmanvar requested a review from sdzhong as a code owner August 21, 2026 10:12
@sentry

sentry Bot commented Aug 21, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
Android com.example.vu.android 24.12.26 (241226) release
Android com.example.vu.android 24.12.26 (241226) debug
Android com.example.vu.android 24.12.26 (241226) release

⚙️ android Build Distribution Settings

@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (21c77a4) to head (b8bacf7).

Files with missing lines Patch % Lines
.../vu/android/empowerplant/EmpowerPlantActivity.java 0.00% 4 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #263   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files         16      16           
  Lines        883     885    +2     
  Branches      67      67           
=====================================
- Misses       883     885    +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant