Reputation:
This project was coped almost exacatly from the example on the admob page but it still does not work! Here is my class file:
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();
}
}
... and my manifest:
<?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>
I dont know what to do, I only get this error in the logcat
java.lang.NoClassDefFoundError: com.google.ads.AdView
What does this mean? Please help!
Upvotes: 0
Views: 280
Reputation: 21087
Make sure that you have copied admob.jar in to the libs folder and don't forget to add admob activity tag in Menifest.xml
<activity
android:name="com.google.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" >
</activity>
Upvotes: 0
Reputation: 67502
You need to include the AdMob SDK in your project. If you're using Eclipse, this tutorial will show you how to do that.
If you don't yet have the SDK downloaded, you can do that from your AdMob control panel, or from here.
Lastly, check your AndroidManifest.xml
file. It should have, added to it, the lines of code bolded in that same tutorial. (Side note: you showed us your layout file, not your manifest.)
Also make sure you have cleaned and rebuilt your project after doing this.
Upvotes: 1