java - Issues with Loading AdMob Ads on App -
i trying have ad banner display on app , seem having issue. anytime go activity, app crashes , mentions when trying load ad, null reference. not positive why though.
here xml adview:
<?xml version="1.0" encoding="utf-8"?> <framelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ads="http://schemas.android.com/apk/res-auto" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/gamelayout"> <com.google.android.gms.ads.adview android:id="@+id/bannerad" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" ads:adsize="banner" ads:adunitid="my_adunitid" /> </framelayout>
here java code using ads:
//load ads adview adview = (adview)findviewbyid(r.id.bannerad); adrequest.builder request = new adrequest.builder(); request.addtestdevice(adrequest.device_id_emulator); adview.loadad(request.build());
here logcat:
09-21 21:55:39.300: e/androidruntime(1168): fatal exception: main 09-21 21:55:39.300: e/androidruntime(1168): process: com.project.llb, pid: 1168 09-21 21:55:39.300: e/androidruntime(1168): java.lang.runtimeexception: unable start activity componentinfo{com.twentytwentythree.sab/com.twentytwentythree.sab.rungraphics}: java.lang.nullpointerexception: attempt invoke virtual method 'void com.google.android.gms.ads.adview.loadad(com.google.android.gms.ads.adrequest)' on null object reference 09-21 21:55:39.300: e/androidruntime(1168): @ android.app.activitythread.performlaunchactivity(activitythread.java:2596) 09-21 21:55:39.300: e/androidruntime(1168): @ android.app.activitythread.handlelaunchactivity(activitythread.java:2653) 09-21 21:55:39.300: e/androidruntime(1168): @ android.app.activitythread.access$800(activitythread.java:156) 09-21 21:55:39.300: e/androidruntime(1168): @ android.app.activitythread$h.handlemessage(activitythread.java:1355) 09-21 21:55:39.300: e/androidruntime(1168): @ android.os.handler.dispatchmessage(handler.java:102) 09-21 21:55:39.300: e/androidruntime(1168): @ android.os.looper.loop(looper.java:157) 09-21 21:55:39.300: e/androidruntime(1168): @ android.app.activitythread.main(activitythread.java:5872) 09-21 21:55:39.300: e/androidruntime(1168): @ java.lang.reflect.method.invoke(native method) 09-21 21:55:39.300: e/androidruntime(1168): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:852) 09-21 21:55:39.300: e/androidruntime(1168): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:668) 09-21 21:55:39.300: e/androidruntime(1168): caused by: java.lang.nullpointerexception: attempt invoke virtual method 'void com.google.android.gms.ads.adview.loadad(com.google.android.gms.ads.adrequest)' on null object reference 09-21 21:55:39.300: e/androidruntime(1168): @ com.twentytwentythree.sab.rungraphics.oncreate(rungraphics.java:94) 09-21 21:55:39.300: e/androidruntime(1168): @ android.app.activity.performcreate(activity.java:5312) 09-21 21:55:39.300: e/androidruntime(1168): @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1111) 09-21 21:55:39.300: e/androidruntime(1168): @ android.app.activitythread.performlaunchactivity(activitythread.java:2552) 09-21 21:55:39.300: e/androidruntime(1168): ... 9 more
here code androidmanifest:
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <activity android:name="com.google.android.gms.ads.adactivity" android:configchanges="keyboard|keyboardhidden|orientation" > </activity>
now using addtestdevice method because assume need use since app not on market place yet. have admob account setup , have banner setup way.
please let me know if have ideas. lot.
r.id.bannerad not available in content have set activity/fragment. prior calling:
adview adview = (adview)findviewbyid(r.id.bannerad);
you must have called
setcontentview(r.layout.mylayoutcontainingbannerad);
Comments
Post a Comment