How to add ads to an android app using eclipse?



I can't add ads to my app using the new admob. I have tried alot of things but they don't work this is what my code is like, this is the conclusion that I ended up with


here is my xml:



<LinearLayout xmlns:android="http://ift.tt/nIICcg"
xmlns:ads="http://ift.tt/GEGVYd"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="3"
android:background="@android:color/background_dark" >

<RelativeLayout
android:id="@+id/adBanner"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:gravity="center">

<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="320dp"
android:layout_height="50dp"
ads:adUnitId="bla bla"
ads:adSize="BANNER"
android:layout_gravity="center"/>

</RelativeLayout>

.......

</LinearLayout>


and I getting an error:



The following classes could not be instantiated:
- com.google.android.gms.ads.AdView


here is my java:



import java.io.IOException;

import com.squareup.picasso.Picasso;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import android.app.Activity;
import android.app.WallpaperManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class MainActivity extends Activity implements OnClickListener {

static int tophone;
ImageView display;
private AdView adView;


protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);


AdRequest adRequest = new AdRequest.Builder()
.build();


AdView adView = (AdView) this.findViewById(R.id.adView);
adView.loadAd(adRequest);

........

@Override
public void onResume() {
super.onResume();
if (adView != null) {
adView.resume();
}
}

@Override
public void onPause() {
if (adView != null) {
adView.pause();
}
super.onPause();
}

@Override
public void onDestroy() {
if (adView != null) {
adView.destroy();
}
super.onDestroy();
}
}


my manifest:



<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://ift.tt/nIICcg"
package="com.StarSurge.khwallpaper"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21"/>
<uses-permission android:name="android.permission.SET_WALLPAPER"/>
<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
</application>

</manifest>


so could anyone tell me what should I do to fix the error and to make the add work?


No comments:

Post a Comment