Webview中的Java nullpointer异常

时间:2015-01-24 16:26:46

标签: android adview

我尝试搜索此问题,但此错误看起来与this error不一样(我的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时出现此错误,但不会出现。这个错误可能来自线程操作吗?知道如何避免这个问题吗?

1 个答案:

答案 0 :(得分:2)

作为https://developer.android.com/reference/com/google/android/gms/ads/AdView.html中的示例和AdView.destroy()的文档,您应该只调用adView.pause()中的onPause(),然后在{{1}中调用adView.destroy() }}

堆栈转储看起来像另一个线程正在访问被破坏的onDestroy()实例。