My xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:orientation="vertical" >
<com.google.ads.AdView android:id="@+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="SMART_BANNER"
ads:adUnitId="@string/admob_unit_id"
ads:testDevices="@string/test_device"
ads:loadAdOnCreate="true"/>
</LinearLayout>
Error in logcat:
11-05 09:32:30.593: I/Ads(2052): adRequestUrlHtml: <html><head><script src="http://media.admob.com/sdk-core-v40.js"></script><script>AFMA_buildAdURL({"preqs":18,"session_id":"1804074505668833558","seq_num":"19","slotname":"a150940f47b619f","u_w":320,"msid":"com.ad.aksharamaala.hd","js":"afma-sdk-a-v6.2.1","bas_off":0,"net":"wi","app_name":"3.android.com.ad.aksharamaala.hd","hl":"en","smart_w":"full","gnt":8,"carrier":"40407","u_audio":3,"kw":[],"u_sd":1,"mv":"8015016.com.android.vending","isu":"EB83E0FCC98011A7D8B65831A838375F","cipa":0,"format":"320x50_mb","oar":0,"smart_h":"auto","ad_pos":{"height":0,"visible":1,"y":480,"x":0,"width":320},"u_h":480,"bas_on":0,"ptime":998246});</script></head><body></body></html>
11-05 09:32:30.953: W/webcore(2052): Can't get the viewWidth after the first layout
11-05 09:32:30.953: I/Ads(2052): Received ad url: <url: "http://googleads.g.doubleclick.net:80/mads/gma?preqs=18&session_id=1804074505668833558&seq_num=19&u_w=320&msid=com.ad.aksharamaala.hd&js=afma-sdk-a-v6.2.1&bas_off=0&net=wi&app_name=3.android.com.ad.aksharamaala.hd&hl=en&smart_w=full&gnt=8&carrier=40407&u_audio=3&kw&u_sd=1&mv=8015016.com.android.vending&isu=EB83E0FCC98011A7D8B65831A838375F&cipa=0&format=320x50_mb&oar=0&smart_h=auto&u_h=480&bas_on=0&ptime=998246&u_so=p&output=html®ion=mobile_app&u_tz=-330&client_sdk=1&ex=1&slotname=a150940f47b619f&kw_type=broad&askip=3&gsb=wi&caps=interactiveVideo_th_mediation_sdkAdmobApiForAds_di&jsv=40" type: "admob" afmaNotifyDt: "null" useWebViewLoadUrl: "false">
11-05 09:32:30.953: I/Ads(2052): Request scenario: Online server request.
11-05 09:32:30.973: W/Ads(2052): IOException connecting to ad url.
11-05 09:32:30.973: W/Ads(2052): java.net.ConnectException: googleads.g.doubleclick.net/127.0.0.1:80 - Connection refused
11-05 09:32:30.973: W/Ads(2052): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:254)
11-05 09:32:30.973: W/Ads(2052): at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:533)
11-05 09:32:30.973: W/Ads(2052): at java.net.Socket.connect(Socket.java:1055)
11-05 09:32:30.973: W/Ads(2052): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:62)
11-05 09:32:30.973: W/Ads(2052): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:88)
11-05 09:32:30.973: W/Ads(2052): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHTTPConnection(HttpURLConnectionImpl.java:927)
11-05 09:32:30.973: W/Ads(2052): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:909)
11-05 09:32:30.973: W/Ads(2052): at com.google.ads.internal.f.b(SourceFile:459)
11-05 09:32:30.973: W/Ads(2052): at com.google.ads.internal.f.run(SourceFile:430)
11-05 09:32:30.973: W/Ads(2052): at java.lang.Thread.run(Thread.java:1096)
11-05 09:32:30.973: D/webviewglue(2052): nativeDestroy view: 0x390bf8
11-05 09:32:30.973: I/Ads(2052): onFailedToReceiveAd(A network error occurred.)
Can anyone tell me where am I making mistake?
if you look closely in the log you posted, on line 6 you will notice that
googleads.g.doubleclick.netresolves to127.0.0.1. This usually means that thehostsfile on your phone was tampered, with the purpose of blocking ads in all your apps.If you’re running this on an emulator, either your emulator’s
hostsfile was tampered, or your computer’s OShostsfile. You should check those out.