java - Android - Google Play Service throw IllegalStateException complaining about size and ad unit id -


since replaced admob library google play service library, android app triggers following exception

java.lang.runtimeexception: unable start activity componentinfo{com.xxx.xxx/com.xxx.xxx.ui.activity.feedactivity}: java.lang.illegalstateexception: ad size , ad unit id must set before loadad called. @ android.app.activitythread.performlaunchactivity(activitythread.java:2328) @ android.app.activitythread.handlelaunchactivity(activitythread.java:2386) @ android.app.activitythread.access$900(activitythread.java:169) @ android.app.activitythread$h.handlemessage(activitythread.java:1277) @ android.os.handler.dispatchmessage(handler.java:102) @ android.os.looper.loop(looper.java:136) @ android.app.activitythread.main(activitythread.java:5476) @ java.lang.reflect.method.invokenative(native method) @ java.lang.reflect.method.invoke(method.java:515) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:1268) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:1084) @ dalvik.system.nativestart.main(native method) caused by: java.lang.illegalstateexception: ad size , ad unit id must set before loadad called. @ com.google.android.gms.internal.ak.an(unknown source) @ com.google.android.gms.internal.ak.a(unknown source) @ com.google.android.gms.ads.adview.loadad(unknown source) @ com.xxx.newslibrary.ui.activity.feedactivity.initactivitylayout(feedactivity.java:255) @ com.xxx.newslibrary.ui.activity.feedactivity.oncreate(feedactivity.java:72) @ android.app.activity.performcreate(activity.java:5451) @ android.app.instrumentation.callactivityoncreate(instrumentation.java:1093) @ android.app.activitythread.performlaunchactivity(activitythread.java:2292) ... 11 more 

basically exception complaining i'm not setting ad size , unit id before loadad. me code:

    madview = new adview(this);     madview.setadsize(adsize.banner);     madview.setadunitid(sourceactivity.application_admob_banner_id);      linearlayout layout = (linearlayout) findviewbyid(r.id.activity_view);     layout.addview(madview);      adrequest adrequest = new adrequest.builder().build();     madview.loadad(adrequest);     madview.setvisibility(view.gone);      madview.setadlistener(new adlistener() {       @override       public void onadloaded() {           log.d(tag, "onadloaded");           madview.setvisibility(view.visible);       }     }); 

as can see, correct. , said before exception doesn't appear in fact appeared few times.

does have idea of might causing this?

change code

                  <com.google.android.gms.ads.adview android:id="@+id/adview"                      android:layout_width="wrap_content"                      android:layout_height="wrap_content"                      android:layout_below="@+id/gridview1"                      ads:adunitid="my id number"                      ads:adsize="banner"/> 

to

                 <com.google.android.gms.ads.adview android:id="@+id/adview"                      xmlns:ads="http://schemas.android.com/apk/res-auto"                      android:layout_width="match_parent"                      android:layout_height="wrap_content"                      ads:adunitid="ca-app-pub-8510605212168324/8634800090"                      ads:adsize="banner"                      android:layout_alignparentbottom="true"                      >                   </com.google.android.gms.ads.adview> 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -