Android app error due to Null Pointer exception when setting onClick listener in editor class

I created a Linear Layout onclick button that has edit text. When you enter text, a popup appears for suggestions that appear and the app crashes.

Stack trace:

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
       at android.widget.Editor$SuggestionsPopupWindow.initContentView(Editor.java:3714)
       at android.widget.Editor$PinnedPopupWindow.(Editor.java:3375)
       at android.widget.Editor$SuggestionsPopupWindow.(Editor.java:3660)
       at android.widget.Editor.replace(Editor.java:423)
       at android.widget.Editor$3.run(Editor.java:2340)
       at android.os.Handler.handleCallback(Handler.java:751)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:154)
       at android.app.ActivityThread.main(ActivityThread.java:6682)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1520)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1410)

      

I found several related answers that said this happens when using Android PopupWindow, as the suggestions use PopupWindow too. My code doesn't use PopupWindow either.

This crash occurs mainly on Samsung Note 5 and Galaxy S6.

Any help would be appreciated!

+3


source to share


2 answers


It is said that your button (which you used as buttonName.setOnClickListener()

) is undefined. Check your search for function id, id inside, etc.



+1


source


I think this is because you have specified a click in the XML but do not have it in your class. The check has this tag and removes:



android:onClick="save"

      

0


source







All Articles