无法在我的应用中获取Admob广告

时间:2012-11-05 04:16:19

标签: android admob

我的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>

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&region=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.)

谁能告诉我哪里出错了?

1 个答案:

答案 0 :(得分:3)

如果仔细查看发布的日志,请在第6行注意googleads.g.doubleclick.net解析为127.0.0.1。这通常意味着您手机上的hosts文件被篡改,目的是阻止所有应用中的广告。

如果您在模拟器上运行此操作,则模拟器的hosts文件被篡改,或者您的计算机的OS hosts文件。你应该检查一下。