react-native-checkbox: NullPointerException Crash in ReactCheckBoxManager on React Native 0.76.1

Description:

We encountered a NullPointerException crash when attempting to interact with the checkbox component in our React Native app. This issue specifically occurs when the ReactCheckBoxManager tries to access the EventDispatcher from a null UIManagerModule reference. This crash has been observed on React Native version 0.76.1.

Stack Trace:

E  FATAL EXCEPTION: main
    Process: com.pokket.challenger.plus, PID: 9991
    java.lang.NullPointerException: Attempt to invoke virtual method 'com.facebook.react.uimanager.events.EventDispatcher com.facebook.react.uimanager.UIManagerModule.getEventDispatcher()' on a null object reference
    	at com.reactnativecommunity.checkbox.ReactCheckBoxManager$1.onCheckedChanged(ReactCheckBoxManager.java:37)
    	at com.reactnativecommunity.checkbox.ReactCheckBox.setChecked(ReactCheckBox.java:27)
    	at android.widget.CompoundButton.toggle(CompoundButton.java:137)
    	at android.widget.CompoundButton.performClick(CompoundButton.java:142)
    	at android.view.View.performClickInternal(View.java:7425)
    	at android.view.View.access$3600(View.java:810)
    	at android.view.View$PerformClick.run(View.java:28305)
    	at android.os.Handler.handleCallback(Handler.java:938)
    	at android.os.Handler.dispatchMessage(Handler.java:99)
    	at android.os.Looper.loop(Looper.java:223)
    	at android.app.ActivityThread.main(ActivityThread.java:7656)
    	at java.lang.reflect.Method.invoke(Native Method)
    	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
    	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

Steps to Reproduce:

  1. Upgrade to React Native 0.76.1.
  2. Integrate the @react-native-community/checkbox package.
  3. Interact with the checkbox component.
  4. Observe the crash occurring on Android.

Expected Behavior:

The checkbox component should work without causing a crash.

Actual Behavior:

The app crashes when attempting to use the checkbox component due to a NullPointerException when accessing the EventDispatcher.

Environment:

  • React Native version: 0.76.1
  • react-native-checkbox: Latest version at the time of writing
  • Platform: Android

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 7
  • Comments: 16 (3 by maintainers)

Commits related to this issue

Most upvoted comments

I managed to work around this issue by placing the CheckBox inside a TouchableOpacity that actually changes the state and setting the CheckBox’s disabled prop to {true}.

@Satyam-code143 , It would be something like this:

const [myState, setMyState] = useState(false);

        <TouchableOpacity
            style={styles.check}
            onPress={() => setMyState(!myState)}
        >
                <CheckBox
                    disabled={true}
                    value={myState}
                    onValueChange={(newValue) => setMyState(newValue)}
                    tintColors={{ true: '#516091', false: '#516091' }}
                />

        </TouchableOpacity>

The app crashes when attempting to use the checkbox component. Any solution???

I used the checkbox from ‘react-native-elements’, tha change was really easy and worked like charm. The main reason for choosing that library was that I was alreading using it for other components.