android:xml中的广告编码,执行时无法显示任何广告

时间:2012-10-09 17:55:54

标签: android admob tablelayout

我尝试将com.google.ads.AdView添加到xml部分,xml编码如下:

<TableLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:id="@+id/tableLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/background_color"
    android:gravity="center_horizontal"
    android:orientation="vertical"
    android:padding="5dp"
    android:stretchColumns="*" >
<TableRow
    <Button android:id="@+id/equal" 
        style="@style/Eq_button_style"
        android:text="=">   
    </Button>
</TableRow>

  <com.google.ads.AdView 
      android:id="@+id/adView"                         
      android:layout_width="wrap_content"                         
      android:layout_height="wrap_content"                         
      ads:adUnitId="a123123123123c"      //this ID is confirmed correct                   
      ads:adSize="BANNER"                         
      ads:testDevices="TEST_EMULATOR, xxxxxxxxxxxxxxxxx"   //this ID is confirmed correct                      
      ads:loadAdOnCreate="true"/>

</TableLayout>

但是,即使应用在运行时没有崩溃,底部也不会显示广告。 logcat如下:

10-10 01:45:16.360: I/GATE(16797): <GATE-M>DEV_ACTION_COMPLETED</GATE-M>
10-10 01:45:16.365: D/webviewglue(16797): nativeDestroy view: 0x3ef6f0
10-10 01:45:16.365: E/Ads(16797): An error occurred while destroying an AdWebView:
10-10 01:45:16.365: E/Ads(16797): java.lang.NullPointerException
10-10 01:45:16.365: E/Ads(16797):   at android.webkit.WebView.setWebViewClient(WebView.java:5168)
10-10 01:45:16.365: E/Ads(16797):   at com.google.ads.internal.AdWebView.destroy(SourceFile:252)
10-10 01:45:16.365: E/Ads(16797):   at com.google.ads.internal.c$e.run(SourceFile:191)
10-10 01:45:16.365: E/Ads(16797):   at android.os.Handler.handleCallback(Handler.java:605)
10-10 01:45:16.365: E/Ads(16797):   at android.os.Handler.dispatchMessage(Handler.java:92)
10-10 01:45:16.365: E/Ads(16797):   at android.os.Looper.loop(Looper.java:137)
10-10 01:45:16.365: E/Ads(16797):   at android.app.ActivityThread.main(ActivityThread.java:4511)
10-10 01:45:16.365: E/Ads(16797):   at java.lang.reflect.Method.invokeNative(Native Method)
10-10 01:45:16.365: E/Ads(16797):   at java.lang.reflect.Method.invoke(Method.java:511)
10-10 01:45:16.365: E/Ads(16797):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
10-10 01:45:16.365: E/Ads(16797):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
10-10 01:45:16.365: E/Ads(16797):   at dalvik.system.NativeStart.main(Native Method)
10-10 01:45:16.365: I/Ads(16797): onReceiveAd()
10-10 01:45:16.460: D/dalvikvm(16797): GC_CONCURRENT freed 424K, 6% free 9580K/10119K, paused 2ms+11ms
10-10 01:45:16.460: W/Ads(16797): Not enough space to show ad! Wants: <480, 75>, Has: <464, 708>

怎么解决?该程序不强制关闭,它仍然可以执行,但广告无法显示。 另外,最后一行Logcat说没有足够的空间?如何为它添加更多空间?我已经预留了很多空间。

非常感谢提前!

修订了logcat:

应用程序仍然可以执行而没有任何错误,但这些“E”部分在某些情况下对应用程序的正确执行有任何影响吗?

10-11 00:52:30.330: E/Ads(10023): An error occurred while destroying an AdWebView:
10-11 00:52:30.330: E/Ads(10023): java.lang.NullPointerException
10-11 00:52:30.330: E/Ads(10023):   at android.webkit.WebView.setWebViewClient(WebView.java:5168)
10-11 00:52:30.330: E/Ads(10023):   at com.google.ads.internal.AdWebView.destroy(SourceFile:252)
10-11 00:52:30.330: E/Ads(10023):   at com.google.ads.internal.c$e.run(SourceFile:191)
10-11 00:52:30.330: E/Ads(10023):   at android.os.Handler.handleCallback(Handler.java:605)
10-11 00:52:30.330: E/Ads(10023):   at android.os.Handler.dispatchMessage(Handler.java:92)
10-11 00:52:30.330: E/Ads(10023):   at android.os.Looper.loop(Looper.java:137)
10-11 00:52:30.330: E/Ads(10023):   at android.app.ActivityThread.main(ActivityThread.java:4511)
10-11 00:52:30.330: E/Ads(10023):   at java.lang.reflect.Method.invokeNative(Native Method)
10-11 00:52:30.330: E/Ads(10023):   at java.lang.reflect.Method.invoke(Method.java:511)
10-11 00:52:30.330: E/Ads(10023):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
10-11 00:52:30.330: E/Ads(10023):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
10-11 00:52:30.330: E/Ads(10023):   at dalvik.system.NativeStart.main(Native Method)

2 个答案:

答案 0 :(得分:2)

确实存在问题:

W/Ads(16797): Not enough space to show ad! Wants: <480, 75>, Has: <464, 708>

对于该设备,您需要整个屏幕宽度才能以纵向显示广告。部分问题是TableLayout上的android:padding="5dp"

答案 1 :(得分:0)

应该是布局问题。 试一试。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TableLayout
        xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
        android:id="@+id/tableLayout"
        android:layout_width="match_parent"
        android:layout_height="0dp"
            android:background="@color/background_color"
        android:layout_weight="1"
        android:gravity="center_horizontal"
        android:orientation="vertical"
        android:padding="5dp"
        android:stretchColumns="*" >

        <TableRow>

            <Button
                android:id="@+id/equal"
                    style="@style/Eq_button_style"
                android:text="=" >
            </Button>
        </TableRow>
    </TableLayout>

    <com.google.ads.AdView
        android:id="@+id/adView"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="a123123123123c"
        ads:loadAdOnCreate="true"
        ads:testDevices="TEST_EMULATOR, xxxxxxxxxxxxxxxxx" />

</LinearLayout>