0

这个项目几乎可以从 admob 页面上的示例中得到解决,但它仍然无法正常工作!这是我的类文件:

 package com.firecow.admobtest;

import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;

import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;

/**
 * A simple {@link Activity} that embeds an AdView.
 */
public class AdMobTesterActivity extends Activity {
    /** The view to show the ad. */
    private AdView adView;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Create an ad.
        adView = new AdView(this, AdSize.BANNER, "a14fd022edb48e8");

        // Add the AdView to the view hierarchy. The view will have no size
        // until the ad is loaded.
        LinearLayout layout = (LinearLayout) findViewById(R.id.mainLayout);
        layout.addView(adView);

        // Create an ad request. Check logcat output for the hashed device ID to
        // get test ads on a physical device.
        AdRequest adRequest = new AdRequest();
        adRequest.addTestDevice(AdRequest.TEST_EMULATOR);

        // Start loading the ad in the background.
        adView.loadAd(adRequest);
    }

    /** Called before the activity is destroyed. */
    @Override
    public void onDestroy() {
        // Destroy the AdView.
        if (adView != null) {
            adView.destroy();
        }

        super.onDestroy();
    }
}

...和我的清单:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mainLayout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />

</LinearLayout>

我不知道该怎么办,我只在logcat中得到这个错误

java.lang.NoClassDefFoundError: com.google.ads.AdView

这是什么意思?请帮忙!

4

2 回答 2

1

您需要在项目中包含 AdMob SDK。如果您使用的是 Eclipse,本教程将向您展示如何做到这一点。

如果您尚未下载 SDK,可以从 AdMob 控制面板或从此处下载。

最后,检查您的AndroidManifest.xml文件。它应该有,添加到它,在同一个教程中加粗的代码行。(旁注:您向我们展示了您的布局文件,而不是您的清单。)

还要确保您在执行此操作后已清理并重建了您的项目。

于 2012-06-14T00:35:03.873 回答
0

确保您已将 admob.jar 复制到 libs 文件夹中,并且不要忘记在 Menifest.xml 中添加 admob 活动标签

<activity
    android:name="com.google.ads.AdActivity"
    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" >
</activity>
于 2013-08-15T12:30:32.253 回答