2011-04-06 59 views
2

我有一個完整的應用程序,我嘗試添加admob。在Android中集成Admob時出錯

我發佈者ID,我已經在清單文件中添加它。當我在設備上運行時,該應用在所有其他活動中都可以正常工作。然而,當我移動到AdMob廣告已被放置,我的應用程序崩潰的活動,並在logcat中它顯示了以下錯誤:

在logcat中顯示的主要錯誤是如下:

04-06 20:22:30.627: ERROR/AndroidRuntime(2339): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mnn.image0114/com.menteon.speedimage0114.ResultPage}: android.view.InflateException: Binary XML file line #8: Error inflating class com.admob.ads.AdView

04-06 20:22:30.627: ERROR/AndroidRuntime(2339): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class com.admob.ads.AdView

04-06 20:22:30.627: ERROR/AndroidRuntime(2339): Caused by: java.lang.ClassNotFoundException: com.admob.ads.AdView in loader [email protected]

如何解決這個錯誤?請幫幫我。

+0

你補充說,AdMob的jar文件? – 2011-04-06 15:27:21

回答

5

如果你使用的是最新的AdMob罐子,你需要使用com.google.ads.AdView。 Sdk 4.04的確如此。

話雖如此,我沒有把我的AdViews直接進入XML,但用下面的代碼到我的XML內放置的LinearLayout裏面的廣告 -

adView = new AdView(this, AdSize.BANNER, MY_ID); 
LinearLayout layout = (LinearLayout) findViewById(R.id.adMob); 
layout.addView(adView); 
AdRequest adRequest = new AdRequest(); 
adRequest.setTesting(GlobalData.DebugBuild); 
adView.loadAd(adRequest); 
+0

這是什麼GlobalData ....我試着用你的答案,但得到這些詞中的紅線 – 2011-04-07 04:23:11

+1

這是一個標誌,我用它來確定我是否正在發佈版本或調試版本。基本上使用'adRequest.setTesting(true)'爲一個調試版本或'adRequest.setTesting(true)'爲一個發佈版本 – Rok 2011-04-07 07:29:13

+0

你能回答我的問題在下面的鏈接http://stackoverflow.com/questions/5576516/ admob-無法在Android中查看 – 2011-04-07 07:34:39

8

我有同樣的問題,並我固定它這裏的操作說明: NoClassDefFoundError when GoogleAnalyticsTracker.getInstance() 看來新版本ADT的17條要求圖書館從項目內的「庫」文件夾導入。所以我剛剛創建了「libs」文件夾,在那裏導入了我的庫,然後將它們設置在項目的構建路徑中(基本上按照上述鏈接中的說明進行)。它解決了我用admob和分析代碼所遇到的兩個問題。

2

爲了解決這個問題,我創建了一個名爲/ libs文件夾和複製GoogleAdMobAdsSdk-6.0.1.jar進去。像魅力一樣工作。

1

是的,我同意與史蒂夫蘇丹。我已經嘗試了對佈局文件中的AdView小部件進行一些額外修改的方法。我得到了這個,http://blog.kerul.net/2012/08/example-how-to-install-google-admob-6x.html ...

我有這種應用程序崩潰和顯示這樣的消息 - 「錯誤膨脹類com.admob.ads.AdView」的經驗。做一些研究和測試我得出以下XML屬性來顯示AdView;

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="match_parent" 
android:background="@drawable/bg1" 
android:orientation="vertical" > 

<TableRow 
    android:id="@+id/tableRow2" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 
    <com.google.ads.AdView 
     xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 
     android:id="@+id/ad" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     ads:adSize="SMART_BANNER" 
     ads:adUnitId="738a44d913034b9f" 
     /> 
</TableRow> 

<TableRow 
    android:id="@+id/tableRow3" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 

    <EditText 
     android:id="@+id/txtsearch" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:inputType="textMultiLine" 
     android:maxLines="3" 
     android:minLines="1" 
     android:scrollbarStyle="outsideOverlay" 
     android:scrollbars="vertical" /> 

</TableRow> 

<TableRow 
    android:id="@+id/tableRow1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 







    <Button 
     android:id="@+id/btnkamus" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:drawableRight="@drawable/search" /> 




    <Button 
     android:id="@+id/btnsearch" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:text="Kesan" /> 


    <Button 
     android:id="@+id/btncadang" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:text="Cadang" /> 

</TableRow> 


<WebView 
    android:id="@+id/webView1" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

</LinearLayout>