Android / Eclipse:无法实例化以下类: - com.google.android.gms.ads.AdView

时间:2014-09-07 05:35:24

标签: android eclipse admob

我正在转换为Google Play服务下的新AdMob,我在图形界面上收到以下错误。我已多次清理该项目,但没有运气。有什么提示吗?

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.ARCompware.shapetapper"
android:versionCode="4"
android:versionName="1.3" >


<uses-sdk
    android:minSdkVersion="9"
    android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>



<application
    android:allowBackup="true"
    android:icon="@drawable/shapetapperlogo"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" android:logo="@drawable/shapetapperlogo"     android:requiredForAllUsers="true"
    >




    <activity
        android:name="com.ARCompware.shapetapper.MainActivity"
        android:configChanges="orientation|keyboardHidden"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.ARCompware.shapetapper.HowToPlay"
        android:label="@string/title_activity_how_to_play"
        android:parentActivityName="com.ARCompware.shapetapper.MainActivity"
        android:screenOrientation="portrait" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.ARCompware.shapetapper.MainActivity" />
    </activity>

    <activity
        android:name="com.ARCompware.shapetapper.GamePlay"
        android:label="@string/title_activity_game_play"
        android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
        android:screenOrientation="portrait" >
    </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>

的活动:

<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:id="@+id/main"
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=".MainActivity" >

<Button
    android:id="@+id/play"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_marginBottom="149dp"
    android:background="#FF0000"
    android:text="PLAY"
    android:textColor="#FFF"
    android:textSize="30dp"
    android:textStyle="bold"
    android:typeface="sans"
    android:onClick="goToPlay" />

<Button
    android:id="@+id/howToPlay"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignTop="@+id/play"
    android:layout_marginTop="60dp"
    android:background="#0000FF"
    android:text="how to play"
    android:textColor="#FFF"
    android:textSize="30dp"
    android:textStyle="bold"
    android:typeface="sans" 
    android:onClick="htp" />

<Button
    android:id="@+id/highScore"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:background="#00FF00"
    android:text="High Score: 0"
    android:textColor="#333"
    android:textSize="30dp"
    android:textStyle="bold"
    android:typeface="sans" />

<ImageView
    android:id="@+id/imgLogo"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_above="@id/play"
    android:background="@drawable/shapetapperlogo"
    />

<com.google.android.gms.ads.AdView
    android:id="@+id/adView"
    android:layout_width="match_parent"
                       android:layout_height="wrap_content"
                       android:layout_below="@id/highScore"
                       ads:adSize="BANNER"
                       ads:adUnitId="ca-app-pub-4718498587561286/4938544884"

                       >
                       </com.google.android.gms.ads.AdView>

</RelativeLayout>

Proguard的:

-keep class * extends java.util.ListResourceBundle {
  protected Object[][] getContents();
}

# Keep SafeParcelable value, needed for reflection. This is required to support backwards
# compatibility of some classes.
-keep public class com.google.android.gms.common.internal.safeparcel.SafeParcelable {
  public static final *** NULL;
}

# Keep the names of classes/members we need for client functionality.
-keepnames @com.google.android.gms.common.annotation.KeepName class *
-keepclassmembernames class * {
  @com.google.android.gms.common.annotation.KeepName *;
}

# Needed for Parcelable/SafeParcelable Creators to not get stripped
-keepnames class * implements android.os.Parcelable {
   public static final ** CREATOR;
}

1 个答案:

答案 0 :(得分:0)

根据这个Link,似乎需要java代码,你需要将它添加到你的onCreate:

AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("TEST_DEVICE_ID")
.build();
adView.loadAd(adRequest);

同时将其添加到您的布局广告视图:

<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
....