我按照所有步骤导入google-play-services,尝试重新安装sdk,重新导入。我尝试添加权重和文本视图以给它空间...我在过去的两天里尝试了所有内容,但是在xml布局的图形界面上不断出现这个错误:
the following classes could not be instantiated: - com.google.android.gms.ads.AdView.
*******清单* / **********
<?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>
***** //////// ***********主要活动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>
答案 0 :(得分:1)
这是因为您在清单文件中添加了错误的活动类。所以只需改变它。
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
答案 1 :(得分:1)
这对我来说是暂时的解决方法。我将Google Play Services SDK的版本从5.x降级回4.x.我使用Intellij Community 13.x和Gradle,所以我的依赖部分现在看起来像这样:
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.+'
}
再次,暂时允许我完成构建XML布局文件。我计划在进入最终测试阶段时升级到最新版本5.x.我已经向Google AdMob广告开发者论坛提出了有关此问题的问题,希望能引起别人的注意。不确定在何处为此特定SDK提交错误报告。 。
答案 2 :(得分:0)
在清单中声明com.google.android.gms.ads.AdActivity
,即。在您的清单文件更改
<activity android:name="com.google.android.gms.ads.AdView"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
到
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
有关详细信息,请参阅Declare com.google.android.gms.ads.AdActivity
还要在xml视图中添加android:id="@+id/adView"
<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>
别忘了清除项目。
有关详细信息,请参阅Create your banner in XML
答案 3 :(得分:0)
转到dimens.xml并将布局边距值从16dp更改为0dp。
答案 4 :(得分:0)
这对我有用:
打开xml布局,切换到文本视图,在预览窗格中单击刷新按钮,问题将得到解决。< / p>
如果问题仍然存在,请确保您的应用的build.gradle文件中包含firebase ads依赖项:
编译'com.google.firebase:firebase-ads:9.8.0'