Android Question What is a "Weak Reference"?

GuyBooth

Active Member
Licensed User
Longtime User
I am using a "pop-up" menu, using the InputMenu library over a CustomListView. Quite frequently - but not always - when I long-click on a menu selection the menu reacts visibly, but the code doesn't work. The app then crashes, and the logs show this message, with "weak reference" in the first line:
B4X:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object java.lang.ref.WeakReference.get()' on a null object reference
    at anywheresoftware.b4a.Msgbox$DialogResponse.onClick(Msgbox.java:119)
    at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:1149)
    at android.widget.AdapterView.performItemClick(AdapterView.java:339)
    at android.widget.AbsListView.performItemClick(AbsListView.java:1550)
    at android.widget.AbsListView$PerformClick.run(AbsListView.java:3721)
    at android.widget.AbsListView$3.run(AbsListView.java:5660)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:6873)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

None of the lines contain any recognisable reference to my own code.
This has been bugging me for (literally) years, and maybe it's time I found out what the problem is. Does anyone have similar experience, or better yet, know what the solution is?
 
Top