react-native-keyevent icon indicating copy to clipboard operation
react-native-keyevent copied to clipboard

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.github.kevinejohn.keyevent.KeyEventModule.onKeyDownEvent(int, android.view.KeyEvent)' on a null object reference

Open ismaelsousa opened this issue 10 months ago • 0 comments

Crashlytics - Stack trace

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.github.kevinejohn.keyevent.KeyEventModule.onKeyDownEvent(int, android.view.KeyEvent)' on a null object reference

How to reproduce it

  1. Hold the button up/down
  2. Open the app by holding the button
  3. The app will crash

How to fix it

check if the instance has been initiated already

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if(KeyEventModule.getInstance() != null) {
        KeyEventModule.getInstance().onKeyUpEvent(keyCode, event);
    }
    
    super.onKeyUp(keyCode, event);
    
    return true;
}

ismaelsousa avatar Apr 05 '24 18:04 ismaelsousa