react-native-context-menu-view icon indicating copy to clipboard operation
react-native-context-menu-view copied to clipboard

Crash - Attempt to invoke interface method 'boolean android.view.ViewParent.showContextMenuForChild(android.view.View, float, float)' on a null object reference

Open iampankajver opened this issue 1 year ago • 0 comments

Fatal Exception: java.lang.NullPointerException: Attempt to invoke interface method 'boolean android.view.ViewParent.showContextMenuForChild(android.view.View, float, float)' on a null object reference
      at android.view.View.showContextMenu(View.java:7739)
      at com.mpiannucci.reactnativecontextmenu.ContextMenuView$1.onSingleTapConfirmed(ContextMenuView.java:56)
      at android.view.GestureDetector$GestureHandler.handleMessage(GestureDetector.java:333)
      at android.os.Handler.dispatchMessage(Handler.java:106)
      at android.os.Looper.loopOnce(Looper.java:211)
      at android.os.Looper.loop(Looper.java:300)
      at android.app.ActivityThread.main(ActivityThread.java:8410)
      at java.lang.reflect.Method.invoke(Method.java)
      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:559)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:954)
try {
                            if (getParent() != null) {
                                showContextMenu(e.getX(), e.getY());
                            } else {
                                Log.e("ContextMenuView", "Parent view is null, cannot show context menu.");
                            }
                        } catch (NullPointerException ex) {
                            Log.e("ContextMenuView", "Failed to show context menu due to null reference", ex);
                        }

I am getting the above error in production for some users, currently, I have added the error handling as shown above. Let me know if there is another solution and release the fix in the upcoming version

iampankajver avatar Oct 08 '24 08:10 iampankajver