0

I'm trying to add ad-mobs ads into my android application I've installed Google play services 17 package and copied the package from the sdk>extras>google>google play service to my work space>myproject>lib>__ and imported the google-play-service_lib file to my workspace. after that I added google-play-service.jar to my project>java build path >libraries and I also checked order and export.

But in vain I'm getting an error in main.xml for Element com.google.andriod.gsm.ads.AdView is unknown but it compiles and launches the activity in emluator but has an runtime error.

I've gone through so many posts but none did make me clear enough.

Here below is the mainfest of my project:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.SAI.banner"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="19" />

 <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="com.SAI.banner.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>

Main.xml :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:background="@drawable/bg"
tools:context="com.SAI.banner.MainActivity$PlaceholderFragment" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="20dp"
    android:text="@string/hello_world" />

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView1"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="60dp"
    ads:adSize="BANNER"
    ads:adUnitId="ca-app-pub-3131326757457805/934xxxxxxx" >
</com.google.android.gms.ads.AdView>

</RelativeLayout>

The MainActivity.java

package com.SAI.banner;

import android.support.v7.app.ActionBarActivity;
import com.google.android.gms.ads.*;
import android.os.Bundle;

public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Look up the AdView as a resource and load a request.
    AdView adView = (AdView)this.findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    adView.loadAd(adRequest);
}
}

Thanks in advance Saikiran. Please help me to solve this.

Roan
  • 1,200
  • 2
  • 19
  • 32
saikiran
  • 3
  • 4
  • this post may help you http://stackoverflow.com/questions/10523703/error-inflating-class-com-google-ads-adview – Giru Bhai Jun 14 '14 at 13:09
  • The google play services project must be referenced as a library project, don't just add the jar: https://developers.google.com/mobile-ads-sdk/docs/ – Ken Wolf Jun 14 '14 at 13:09
  • @KenWolf thanxx for the suggestion i have made the changes but still having the same runtime error. – saikiran Jun 14 '14 at 13:22
  • Also make sure you are not confusing your fragment xml with your activity xml. – Ken Wolf Jun 14 '14 at 13:28
  • @KenWolf as i am new to this andriod ADT please explain me should i use fragment xml or activity xml. – saikiran Jun 14 '14 at 15:09

1 Answers1

2

I had this problem. My problem was solved when I added the google play services with following steps:

  1. Import google Play Services as project. Don't forget to check 'Copy Project to your workspace' option
  2. Right click on your app project and click Properties. Select Android. Click 'Add library'. Select google play services from list.
  3. You should make sure that you remove Jar if you have included previously.
  4. Clean your project and build again.
Kanhaiya
  • 58
  • 5