Skip to content

Fix NullPointerException in cart badge update - #245

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
nullpointerexception-attempt-to-0wxcem
Draft

Fix NullPointerException in cart badge update#245
cursor[bot] wants to merge 1 commit into
mainfrom
nullpointerexception-attempt-to-0wxcem

Conversation

@cursor

@cursor cursor Bot commented Jul 27, 2026

Copy link
Copy Markdown

Summary

This PR fixes a NullPointerException that occurs when updating the cart badge in EmpowerPlantActivity.

Problem

The crash occurred because:

  1. onResume() subscribes to StoreItemDAO.observeSelectedCount() which emits immediately
  2. The observer callback tries to update textCartItemCount TextView
  3. However, textCartItemCount is only initialized in onCreateOptionsMenu(), which runs after onResume() in the Activity lifecycle
  4. This resulted in setText() being called on a null reference

Solution

Added a null check before updating the TextView in the observer callback. If the menu hasn't been created yet, the update is skipped. The badge will be updated correctly on subsequent emissions after the menu is initialized.

Changes

  • Added null guard around textCartItemCount.setText() in the RxJava observer

Fixes ANDROID-JA

Open in Web Open in Cursor 

Add null check before updating textCartItemCount TextView to prevent
NullPointerException when observer fires in onResume before
onCreateOptionsMenu initializes the view.

The issue occurred because:
- onResume subscribes to StoreItemDAO.observeSelectedCount()
- Observer emits immediately upon subscription
- onCreateOptionsMenu (which initializes textCartItemCount) runs after onResume
- setText() was called on null reference causing crash

Fixes [ANDROID-JA](https://demo.sentry.io/issues/7591013844/)
@sentry

sentry Bot commented Jul 27, 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 Jul 27, 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 (410e6f1) to head (54f0924).

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