我創建了一個線性佈局onclick按鈕,它具有編輯文本。輸入時會出現一個彈出窗口,提示有關應用程序崩潰的建議。Android應用程序崩潰,因爲空指針異常在編輯器類中設置onClick偵聽器
堆棧跟蹤:
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)
我發現其中指出,這種情況在使用Android PopupWindow類,因爲這些建議是使用PopupWindow以及一些相關的答案。我的代碼也不使用PopupWindow。
這次崩潰主要發生在三星Note 5和Galaxy S6上。
任何幫助,將不勝感激!
原因是當您添加單擊偵聽器時,視圖對象爲空。 在將偵聽器設置爲查看對象之前進行空檢查。 –
請繼續併發布您的java和xml代碼 –
可能的重複[什麼是NullPointerException,以及如何解決它?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-和如何-DO-I-FIX-IT) –