17

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

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

然后出现bug。src可以从这里下载。异常是这样的:

 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 中使用带有 ListFragment 的 adwhirl 时才会出现此异常。如果我只在 ListFragment 中使用或在 ViewPager 中使用 Fragment,它可以正常工作。但我仍然想知道出了什么问题,我该如何解决这个异常。

任何答案将不胜感激。

4

3 回答 3

1
  1. 确保在 onDestory() 方法中处理 AdWhirl
  2. 使用 try catch 来捕获 NullPointer,联系开发人员并希望他们能解决这个问题(如果它是一个错误)
于 2012-07-01T22:23:23.193 回答
0

始终检查承载连接到服务的对象的内容

if(conection !=null){
execute();
}

因为您使用 webView 总是在执行之前检查您的电话连接是否打开,这应该停止空指针

如果没有代码示例,很难给出更好的见解

但是您可以使用下面的连接管理器进行检查,这是如何检查 wifi 的示例

public boolean isOnWifi(Context context) {
    ConnectivityManager connManager = (ConnectivityManager) context
            .getSystemService(CONNECTIVITY_SERVICE);
    NetworkInfo mWifi = connManager
            .getNetworkInfo(ConnectivityManager.TYPE_WIFI);

    if (mWifi.isConnected()) {
        return true;
    }

    return false;
}

要查看是否有蜂窝连接,只需将 ConnectivityManager.TYPE_WIFI 更改为 ConnectivityManager.TYPE_MOBILE

于 2012-07-10T16:00:00.487 回答
0

查找 AdMob 或 AdWhirl 尝试每隔几秒或几分钟更改一次广告横幅的功能。发生此异常是因为该函数中没有异常处理程序。关闭 wifi 后,一些代码需要正常工作的互联网连接,但不再有连接。最好试试这个:

  1. 转到每 x 秒/分钟更改一次广告横幅的功能。
  2. 在那里你必须用异常处理程序包围代码,例如try/catch。并捕获 NullPointerException。
于 2012-10-25T20:50:35.523 回答