我试图搜索这个问题,但这个错误看起来与这个错误 https://stackoverflow.com/questions/21866459/android-nullpointerexception-on-webview(我的 google play 版本较新,请注意该错误位于 WebViewClassic 的不同行,因此可能是不同的错误或在较新版本中相同)但我从 webview 收到了完全相同的错误异常
java.lang.NullPointerException
at android.webkit.WebViewClassic$WebViewInputConnection.setNewText(WebViewClassic.java:583)
at android.webkit.WebViewClassic$WebViewInputConnection.setComposingText(WebViewClassic.java:323)
at android.webkit.WebViewClassic$WebViewInputConnection.commitText(WebViewClassic.java:339)
at com.android.internal.view.IInputConnectionWrapper.executeMessage(IInputConnectionWrapper.java:279)
at com.android.internal.view.IInputConnectionWrapper$MyHandler.handleMessage(IInputConnectionWrapper.java:77)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5297)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
at dalvik.system.NativeStart.main(Native Method)
但是我没有直接使用任何 webview 类。但是,这个问题可能与 AdView 有关,但我不明白如何。我的代码如下:
@Override
public void onPause() {
//TODO: these lines are created because onPuase of Adview doesn't work
if ( adView != null ) {
adView.pause();
adView.destroy();
adView = null;
Log.i(ApplicationData.APP_TAG, TAG + ": OnPause, pausing the Adview");
}
super.onPause();
}
该错误出现在 Log.i 行之后,我本以为该错误会在调用 AdView 时出现,但不会在之后出现。该错误是否可能来自线程操作?知道如何避免这个问题吗?
正如中的例子https://developer.android.com/reference/com/google/android/gms/ads/AdView.html https://developer.android.com/reference/com/google/android/gms/ads/AdView.html以及文件AdView.destroy() https://developer.android.com/reference/com/google/android/gms/ads/AdView.html#destroy(),你应该只调用adView.pause()
in onPause()
,并致电adView.destroy()
后来在onDestroy()
.
堆栈转储看起来像是另一个线程正在访问被破坏的AdView
实例。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)