Skip to content

Fix NullPointerException in EmpowerPlantActivity cart count observer - #264

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

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

Conversation

@cursor

@cursor cursor Bot commented Aug 21, 2026

Copy link
Copy Markdown

Problem

In EmpowerPlantActivity, the cart count observer fires in onResume before onCreateOptionsMenu initializes textCartItemCount, causing a NullPointerException when the cart has items on activity startup.

Root Cause

  1. The cart item count observer fires in onResume before the options menu is inflated
  2. onCreateOptionsMenu (which initializes textCartItemCount) runs after onResume in the Activity lifecycle
  3. The observer calls setText() on a null textCartItemCount reference
  4. No guard exists to defer or skip the UI update when the menu view has not yet been created

Solution

Added a null check for textCartItemCount before calling setText() in the observer within onResume. This prevents the crash while allowing the UI to update once the menu is created.

Testing

  • Launch the Android app and open EmpowerPlantActivity
  • Ensure the cart has items (observer will fire with a count on resume)
  • The activity no longer crashes on startup

Fixes ANDROID-HZ

Open in Web Open in Cursor 

Add null check for textCartItemCount before calling setText() in onResume.
The observer fires before onCreateOptionsMenu initializes the TextView,
causing a crash when the cart has items on activity startup.

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 (6377337).

Files with missing lines Patch % Lines
.../vu/android/empowerplant/EmpowerPlantActivity.java 0.00% 4 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #264   +/-   ##
=====================================
  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