Reputation: 47
Like the title says, I am requesting ads, they are being filled, but never displayed. I even enabled a house ad just to make sure. I have been screwing with this for 2 days now and cant find the solution. I am aware things changed recently with admob and attrs.xml is not longer required to make it work and now have a mess of code with no results. Any help would be appreciated!
Java code:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
//admob
//AdView adView = (AdView)findViewById(R.id.adView1);
AdView adView = new AdView(this, AdSize.BANNER, "a14dd7f0258a8b7");
AdRequest re = new AdRequest();
re.setTesting(true);
adView.loadAd(re);
//end admob
}
AndroidManifest.XML
<application
android:icon="@drawable/icon"
android:label="@string/app_name"
android:debuggable="false"
android:description="@string/description">
<activity
android:label="@string/app_name"
android:screenOrientation="portrait"
android:name=".Index">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation"/>
</application>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</manifest>
main.xml
<LinearLayout
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:orientation="vertical"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:android="http://schemas.android.com/apk/res/android">
<com.google.ads.AdView
android:id="@+id/adView1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
ads:adSize="BANNER"
ads:adUnitId="a14dd7f0258a8b7"
ads:loadAdOnCreate="true"/>
(buttons here)
</LinearLayout>
Update: logCat =
05-22 15:57:22.882: WARN/Ads(294): Invalid adSize parameter in XML layout: -1. Defaulting to BANNER.
05-22 15:57:22.892: ERROR/Ads(294): AdView missing required XML attribute adUnitId.
05-22 15:57:23.512: INFO/Ads(294): adRequestUrlHtml: <html><head><script src="http://www.gstatic.com/afma/sdk-core-v40.js"></script><script>AFMA_buildAdURL({"preqs":1,"u_sd":1.5,"u_w":480,"slotname":"a14dd7f0258a8b7","simulator":1,"msid":"com.robores.elect","cap":"m,a","js":"afma-sdk-a-v4.0.4","isu":"B3EEABB8EE11C2BE770B684D95219ECB","format":"320x50_mb","net":"ed","app_name":"4.0.4.android.com.robores.elect","hl":"en","u_h":800,"testing":1,"u_so":"p","u_audio":4});</script></head><body></body></html>
05-22 15:57:25.113: INFO/Ads(294): Received ad url: <"url": "http://r.admob.com:80/ad_source.php?preqs=1&u_sd=1.5&u_w=480&slotname=a14dd7f0258a8b7&msid=com.robores.elect&cap=m%2Ca&js=afma-sdk-a-v4.0.4&isu=B3EEABB8EE11C2BE770B684D95219ECB&format=320x50_mb&net=ed&app_name=4.0.4.android.com.robores.elect&hl=en&u_h=800&u_so=p&u_audio=4&adtest=on&output=html®ion=mobile_app&u_tz=0&ex=1&client_sdk=1&askip=1", "afmaNotifyDt": "null">
05-22 15:57:25.763: INFO/global(294): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.
05-22 15:57:25.913: DEBUG/dalvikvm(294): GC_FOR_MALLOC freed 6570 objects / 467056 bytes in 94ms
05-22 15:57:25.953: DEBUG/webviewglue(294): nativeDestroy view: 0x291bf8
05-22 15:57:25.953: DEBUG/webviewglue(294): nativeDestroy view: 0x291a40
05-22 15:57:26.513: WARN/webcore(294): Can't get the viewWidth after the first layout
05-22 15:57:26.563: INFO/Ads(294): onReceiveAd()
Upvotes: 1
Views: 4447
Reputation: 11
Using the following , I fixed this error.
<com.google.ads.AdView
android:id="@+id/adView"
android:layout_width="320dp"
android:layout_height="50dp"
android:gravity="center"
ads:adUnitId="my id goes here"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"/>
Upvotes: 0
Reputation: 1292
Which version of the admob lib are you using. There are some difference between GoogleAdMobAdsSdk-4.1.0.jar and GoogleAdMobAdsSdk-4.0.4.jar.
I recently updated from 4.0.4. to 4.1.0 and had to change some lines of code. Currently I've got almost exact the same code as you described above with no problems with 4.1.0.
Upvotes: 2
Reputation: 10948
This works for me:
ad = new AdView(this, AdSize.BANNER, ADMOB_KEY);
LinearLayout layout = (LinearLayout) findViewById(R.id.main_admob_layout);
// Add the adView to it
layout.addView(ad);
AdRequest request = new AdRequest();
request.setKeywords(MosaicCommon.AD_KEYWORDS);
You don't have the addView(..)
part in yours.
Upvotes: 0