从网页视图的Java空指针异常 [英] Java nullpointer exception from Webview

查看:373
本文介绍了从网页视图的Java空指针异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图寻找这个问题,但这个错误不会看起来是一样的这个错误(我的谷歌游戏版本更新,并注意该错误是在不同的线路WebViewClassic的,所以可能不同的错误或更新的版本一样),但我收到的WebView完全相同的错误异常

I tried to search for this problem but this error doesn't look to be the same as this error (my google play version is newer and notice that the error is at a different line of WebViewClassic, so might be different error or the same in a newer version) but I have received the exactly same error exception from 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)

不过我并没有直接使用任何web视图类。不过,这个问题可能与AdView的,但我不知道怎么样。我的code是以下内容:

However I am not using any webview class directly. However, this problem might be related to AdView, but I don't understand how. My code is the following:

 @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被称为而不之后。可能正是这个错误是从螺纹动作来吗?任何想法如何避免这个问题?

The error appears after the Log.i line, I would have expected this error to appear when AdView was called but not after. Is possible that this error is coming from a threaded action? Any idea how to avoid the problem?

推荐答案

作为的 https://developer.android.com/reference/com/google/android/gms/ads/AdView.html 和的 AdView.destroy() ,你应该只调用 adView.pause()的onPause(),并调用 adView.destroy()后面的onDestroy()

As the example in https://developer.android.com/reference/com/google/android/gms/ads/AdView.html and the document for AdView.destroy(), you should only call adView.pause() in onPause(), and call adView.destroy() later in onDestroy().

堆栈转储看起来像另一个线程访问摧毁的AdView 实例。

The stack dump looks like another thread is accessing the destroyed AdView instance.

这篇关于从网页视图的Java空指针异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆