我在自己的一个应用程序中使用了AdWhirl和Admob,发布后,我们从adwhirl中得到很多错误,并且易于重现,如下所示:

广告出现后,我关闭wifi,等待广告超时,然后按返回按钮退出应用程序。

然后该错误就会出现。src可以从this下载。异常(exception)是这样的:

 05-17 11:00:13.265: E/AndroidRuntime(12482): java.lang.RuntimeException: Unable to destroy activity {me.test.admob/me.test.admob.AdWhirlTestActivity}: java.lang.NullPointerException
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3112)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.app.ActivityThread.handleDestroyActivity(ActivityThread.java:3130)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.app.ActivityThread.access$1200(ActivityThread.java:123)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1180)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.os.Looper.loop(Looper.java:137)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.app.ActivityThread.main(ActivityThread.java:4424)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at java.lang.reflect.Method.invokeNative(Native Method)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at java.lang.reflect.Method.invoke(Method.java:511)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at dalvik.system.NativeStart.main(Native Method)
05-17 11:00:13.265: E/AndroidRuntime(12482): Caused by: java.lang.NullPointerException
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.webkit.WebView.requestFocus(WebView.java:7650)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2154)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.view.ViewGroup.requestFocus(ViewGroup.java:2110)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2154)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.view.ViewGroup.requestFocus(ViewGroup.java:2110)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2154)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.view.ViewGroup.requestFocus(ViewGroup.java:2110)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2154)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.view.ViewGroup.requestFocus(ViewGroup.java:2110)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2154)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.view.ViewGroup.requestFocus(ViewGroup.java:2110)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2154)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.view.ViewGroup.requestFocus(ViewGroup.java:2110)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.view.ViewGroup.onRequestFocusInDescendants(ViewGroup.java:2154)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.view.ViewGroup.requestFocus(ViewGroup.java:2113)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.view.View.requestFocus(View.java:5323)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.view.ViewRootImpl.clearChildFocus(ViewRootImpl.java:2200)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.view.ViewGroup.clearChildFocus(ViewGroup.java:669)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.view.ViewGroup.clearChildFocus(ViewGroup.java:669)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.view.ViewGroup.clearChildFocus(ViewGroup.java:669)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.view.ViewGroup.clearChildFocus(ViewGroup.java:669)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.view.ViewGroup.clearChildFocus(ViewGroup.java:669)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.view.ViewGroup.removeViewInternal(ViewGroup.java:3591)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.view.ViewGroup.removeViewInternal(ViewGroup.java:3561)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.view.ViewGroup.removeView(ViewGroup.java:3509)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:998)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.support.v4.app.FragmentManagerImpl.dispatchDestroy(FragmentManager.java:1843)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.support.v4.app.FragmentActivity.onDestroy(FragmentActivity.java:314)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.app.Activity.performDestroy(Activity.java:4629)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.app.Instrumentation.callActivityOnDestroy(Instrumentation.java:1079)
05-17 11:00:13.265: E/AndroidRuntime(12482):    at android.app.ActivityThread.performDestroyActivity(ActivityThread.java:3099)
05-17 11:00:13.265: E/AndroidRuntime(12482):    ... 11 more

经过测试,我发现此异常仅在ViewPager中将adwhirl与ListFragment一起使用时出现。如果我仅在ListFragment中使用,或在ViewPager中使用Fragment,则可以正常工作。
但是我仍然想知道出了什么问题,以及如何解决此异常。

任何答案将不胜感激。

最佳答案

  • 确保您在onDestory()方法
  • 中处理AdWhirl
  • 使用try catch来捕获NullPointer,联系开发者并希望他们能够解决此问题(如果是错误的话)
  • 关于android - AdWhirl导致网络关闭后导致java.lang.NullPointerException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10629329/

    10-11 14:14