17

I use AdWhirl and Admob in one of my app,after release, we get a lot of error from adwhirl,and It's reproduce easily like this:

After ad appear,I shutdown wifi,and wait ad timeout,then press back button to exit application.

then the bug appear.the src can download from this.and the exception is like this:

 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

After my test,I find this exception only appears when use adwhirl with ListFragment in ViewPager.,if I only use in ListFragment or use Fragment in ViewPager,It's work normally. But i still want to know what's wrong,and how can I solve this exception.

Any answer will be appreciate.

notenking
  • 418
  • 3
  • 12
  • Are you making sure you call destroy on your admob adview in onPause or onDestroy? Actually looks like you're doing something wrong in onDestroy() maybe. Did you override onDestroy? If so, post it please. – LuxuryMode Jun 11 '12 at 14:27
  • no,I just exit without do anythings. the src can be find in https://github.com/notenking/AdWhirlException/blob/master/src/me/test/admob/AdWhirlTestActivity.java – notenking Jun 12 '12 at 10:13

3 Answers3

1
  1. make sure you handle AdWhirl in your onDestory() Method
  2. use a try catch to catch the NullPointer, contact the devlopers and hope that they will fix this (if it is a bug)
paulgavrikov
  • 1,883
  • 3
  • 29
  • 51
  • 1
    This bug can be remove in many ways without try catch,but I want to know the best method to remove it Or the really reasons lead to this. – notenking Jul 09 '12 at 14:31
0

Allways check the content of the object that bears the conection to the service

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

because your using a webView always check that your phones conection is on before executing this should stop the nullpointer

it's hard to give a better insight without an example of your code

but you could check using the connectivity manager down bellow is an example how to check for 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;
}

to see if there is an cellular connection just change ConnectivityManager.TYPE_WIFI to ConnectivityManager.TYPE_MOBILE

B. TIger
  • 459
  • 3
  • 10
  • 27
  • How about putting some effort into your answer? Fix typos and especially provide code that at least has no syntax errors?! – WarrenFaith Oct 25 '12 at 20:53
0

Look for a function where AdMob or AdWhirl is trying to change the ad banner every several seconds or minutes. This exception happens because there is no exception handler in that function. After you turn off your wifi, some code is expecting a properly working internet connection, but there is no connectivity anymore. At best try this:

  1. Go to the function where the ad banner is changed every x seconds / minutes.
  2. There you have to surround the code with a exception handler, e.g. try / catch. And catch the NullPointerException.
Martin
  • 11
  • 1
  • 1