Android Question AdMob crashes on Activity_Pause

andyr00d

Member
Licensed User
Longtime User
Hi,

Not sure what I did wrong, but for some reason my app will crash with a NullPointerException when my app is paused (inactivity). It's failing in the Activity_Pause sub.

I'm calling it in Activity_Create and the ad is loaded with no problems... I don't know what's going on :/

B4X:
Sub Activity_Pause (UserClosed As Boolean)

AdView1.Pause

End Sub
 

andyr00d

Member
Licensed User
Longtime User
Hi @Erel

In this case, when I pushed the power/lock button on my phone while my app was running the error appeared.

** Activity (settings) Pause, UserClosed = false **
Error occurred on line: 1323 (settings)
java.lang.NullPointerException: Attempt to read from field 'anywheresoftware.b4a.admobwrapper.AdViewWrapper net.urbancohort.unmotivatedjapanese.settings._adview1' on a null object reference
at net.urbancohort.unmotivatedjapanese.settings._activity_pause(settings.java:967)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at anywheresoftware.b4a.ShellBA$2.run(ShellBA.java:103)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
** Activity (main) Pause, UserClosed = false **

It wasn't doing this initially after I added AdMob, and I can't think of anything I changed to make this happen... any ideas?

Thanks,
 
Upvote 0

Rusty

Well-Known Member
Licensed User
Longtime User
Did you ever solve this? I'm getting the same error.
Code is already working and deployed, I'm just stepping through (debug) existing and working code...
Thanks,

PS it works in release mode, but not in Debug mode...
One thing else that might be important, I am starting an activity from within the MAIN Activity_Create function...
 
Last edited:
Upvote 0
Top