2011-01-11 62 views
0

這是我第一次嘗試在我的應用中加入廣告。我已閱讀在線文檔並逐字閱讀。現在,我沒有得到的唯一部分是如何實際請求廣告並將其添加到我的應用中。Android admob adview force close

AdView adView = (AdView)findViewById(R.id.ad); 

這似乎工作到目前爲止很好。 我做的任何事情只會迫近。 例如加入這一行:

adView.setAdListener(this); 

我已經實現AdListener的到活性的影響。

順便說一句,當我將鼠標懸停在導入的類:

import com.admob.android.ads.AdView; 

或其他類似的類,它說:注意:該元素既不具有附加源也沒有附着的Javadoc,因此沒有Javadoc中可以找到。

這應該是正確的嗎?

+0

你能提供的崩潰日誌?該筆記是正常的。 – 2011-01-11 03:43:12

+0

01-10 20:20:11.152:ERROR/AndroidRuntime(2043):at com.admob.android.ads.AdView。 (AdView.java:323) 01-10 20:20:11.152:ERROR/AndroidRuntime(2043):at com.admob.android.ads.AdView。 (AdView.java:308) 01-10 20:20:11.152:ERROR/AndroidRuntime(2043):at com.admob.android.ads.AdView。 (AdView.java:267) 對不起,以前從未發佈過日誌... – semajhan 2011-01-11 03:50:24

回答

2

這很難說肯定沒有看到你的代碼,你的佈局,但這裏有一些東西,你可能要檢查:

1)AdMobActivity宣佈在AndroidManifest:

​​

2)你要求INTERNET權限在AndroidManifest:

<uses-permission android:name="android.permission.INTERNET" /> 

3)你attrs.xml文件包含必要的樣式:

<?xml version="1.0" encoding="utf-8"?> 
<resources> 
    <declare-styleable name="com.admob.android.ads.AdView"> 
     <attr name="backgroundColor" format="color" /> 
     <attr name="primaryTextColor" format="color" /> 
     <attr name="secondaryTextColor" format="color" /> 
     <attr name="keywords" format="string" /> 
     <attr name="refreshInterval" format="integer" /> 
    </declare-styleable> 
</resources> 

4)你的AdView包含在你的佈局:

<com.admob.android.ads.AdView 
    android:id="@+id/ad" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    myapp:backgroundColor="#000000" 
    myapp:primaryTextColor="#FFFFFF" 
    myapp:secondaryTextColor="#CCCCCC" 
/> 

5)你的AdView被正確發現:

AdView adView = (AdView)findViewById(R.id.ad); 
if (adView == null) { 
    Log.e(TAG, "AdView not found!"); 
}