Reputation: 43
I followed all the steps to import google-play-services, tried re-installing sdk, re-importing. I tried adding weight and text-views to give it space... I tried everything for the past 2 days, but keep getting this error on the graphical interface of the xml layout saying:
the following classes could not be instantiated: - com.google.android.gms.ads.AdView.
*******manifest*/**********
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.alphaking.xxxxxxe"
android:versionCode="1"
android:versionName="1.0" >
<uses-feature android:name="android.hardware.sensor.accelerometer" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar" >
<activity
android:screenOrientation="portrait"
android:name="xxxxxxxxxe.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.STARTINGPOINTS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:screenOrientation="portrait"
android:name="com.alphaking.ijumprope.Settings"
android:label="@string/app_name" >
</activity>
<activity
android:screenOrientation="portrait"
android:name="com.alphaking.ijumprope.Start"
android:label="@string/app_name" >
</activity>
<activity
android:screenOrientation="portrait"
android:name="xxxxxxxxxxxxx.Logs"
android:label="@string/app_name" >
</activity>
<activity
android:screenOrientation="portrait"
android:name="cxxxxxxxxe.About"
android:label="@string/app_name" >
</activity>
<activity
android:screenOrientation="portrait"
android:name="xxxxxxxxxxx.Splash"
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"/>
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version"/>
</application>
</manifest>
*****////////***********main activity java**********************
package cxxxxxxxxxxxxxxxxxxx;
import com.alphxxxxxxgxxxxxxxxxx;
import com.google.android.gms.ads.*;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity{
Button setting,start,logs,about;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AdView adView = (AdView) this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
setting=(Button) findViewById(R.id.button2);
setting.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try{
Class ourClass = Class.forName("com.xxxxxxxxxxxxx.Settings");
Intent ourIntent = new Intent(MainActivity.this, ourClass);
startActivity(ourIntent);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
}
});
start=(Button) findViewById(R.id.button1);
start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try{
Class ourClass = Class.forName("com.alphaking.ijumprope.Start");
Intent ourIntent = new Intent(MainActivity.this, ourClass);
startActivity(ourIntent);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
}
});
logs=(Button) findViewById(R.id.button3);
logs.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try{
Class ourClass = Class.forName("cxxxxxxxxxxxx
Intent ourIntent = new Intent(MainActivity.this, ourClass);
startActivity(ourIntent);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
}
});
about=(Button) findViewById(R.id.button4);
about.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try{
Class ourClass = Class.forName("xxxxxxxxxxxxxxAbout");
Intent ourIntent = new Intent(MainActivity.this, ourClass);
startActivity(ourIntent);
}catch(ClassNotFoundException e){
e.printStackTrace();
}
}
});
}
public void onBackPressed() {
}
}
**********************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"
tools:context="com.alphaking.xxxxxxxxxxxxxActivity"
android:background="@drawable/back"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >
<Button
android:id="@+id/button1"
android:layout_width="120dp"
android:layout_height="60dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:background="@drawable/start" />
<Button
android:id="@+id/button2"
android:layout_width="120dp"
android:layout_height="60dp"
android:layout_alignLeft="@+id/button1"
android:layout_below="@+id/button1"
android:layout_marginTop="30dp"
android:background="@drawable/setup" />
<Button
android:id="@+id/button3"
android:layout_width="120dp"
android:layout_height="60dp"
android:layout_alignLeft="@+id/button2"
android:layout_below="@+id/button2"
android:layout_marginTop="30dp"
android:background="@drawable/logs" />
<Button
android:id="@+id/button4"
android:layout_width="120dp"
android:layout_height="60dp"
android:layout_alignLeft="@+id/button3"
android:layout_below="@+id/button3"
android:layout_marginTop="30dp"
android:background="@drawable/about" />
<com.google.android.gms.ads.AdView
android:layout_width="320dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-1278770925901425/7987430192"
ads:loadAdOnCreate="true"
android:gravity="center" >
</com.google.android.gms.ads.AdView>
</RelativeLayout>
Upvotes: 1
Views: 4410
Reputation: 12031
This worked for me:
Open your xml layout, Switch to Text view, On the Preview pane click the Refresh button and the problem will be solved.
If the problem persists, make sure you have the firebase ads dependency in your app's build.gradle file:
compile 'com.google.firebase:firebase-ads:9.8.0'
Upvotes: 0
Reputation: 316
This is a temporary work-around for me. I downgraded the version of Google Play Services SDK from 5.x back to 4.x. I use Intellij Community 13.x with Gradle so my dependency section looks like this now:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:20.0.0'
compile 'com.android.support:appcompat-v7:20.0.0'
compile 'com.google.android.gms:play-services:4.+'
}
Again, just temporary to allow me to finish building my XML layout files. I plan to upgrade to the latest version 5.x when I enter my final testing phase. I have filed issues about this problem with the Google AdMob Ads Developers forum in hopes of getting someone's attention. Not exactly sure where to file a bug report for this specific SDK. .
Upvotes: 1
Reputation: 263
Go to dimens.xml and change layout margin value from 16dp to 0dp.
Upvotes: 1
Reputation: 14408
Declare com.google.android.gms.ads.AdActivity
in the manifest,i.e. in your manifest file change
<activity android:name="com.google.android.gms.ads.AdView"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
to
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
For more info see Declare com.google.android.gms.ads.AdActivity
Also add android:id="@+id/adView"
in your xml view as
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="320dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-1278770925901425/7987430192"
ads:loadAdOnCreate="true"
android:gravity="center" >
</com.google.android.gms.ads.AdView>
And don't forget to clear project.
For more info see Create your banner in XML
Upvotes: 0
Reputation: 18923
This is because you have added wrong activity class in your manifest file. So just change it with this.
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
Upvotes: 1