在eclipse中运行Activity时出现Google AdMob错误

时间:2016-03-30 06:14:10

标签: android admob

这是由 IntroActivity MainActivity 这两项活动构成的。 我在 MainActivity 中加入 AdMob

我添加了库'google-play-services_lib'但是我在java构建路径中删除了android依赖项,因为它与'google-play-service_lib'冲突了

Android私立图书馆已经有google-play-services.jar了。 我在activity_main.xml上删除了关于com.google.android.gms.adv.Adviw布局的2行。

**Here is error:**


    03-30 01:21:18.113: D/OpenGLRenderer(23904): Use EGL_SWAP_BEHAVIOR_PRESERVED: true
    03-30 01:21:18.127: D/Atlas(23904): Validating map...
    03-30 01:21:18.150: I/Adreno-EGL(23904): <qeglDrvAPI_eglInitialize:379>: QUALCOMM Build: 01/15/15, ab0075f, Id3510ff6dc
    03-30 01:21:18.151: I/OpenGLRenderer(23904): Initialized EGL, version 1.4
    03-30 01:21:18.170: D/OpenGLRenderer(23904): Enabling debug mode 0
    03-30 01:21:20.287: D/AndroidRuntime(23904): Shutting down VM
    03-30 01:21:20.290: E/AndroidRuntime(23904): FATAL EXCEPTION: main
    03-30 01:21:20.290: E/AndroidRuntime(23904): Process: com.jd.agecalculator, PID: 23904
    03-30 01:21:20.290: E/AndroidRuntime(23904): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.jd.agecalculator/com.jd.agecalculator.MainActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class com.google.android.gms.ads.AdView
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2325)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2387)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at android.app.ActivityThread.access$800(ActivityThread.java:151)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1303)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at android.os.Handler.dispatchMessage(Handler.java:102)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at android.os.Looper.loop(Looper.java:135)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at android.app.ActivityThread.main(ActivityThread.java:5254)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at java.lang.reflect.Method.invoke(Native Method)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at java.lang.reflect.Method.invoke(Method.java:372)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
    03-30 01:21:20.290: E/AndroidRuntime(23904): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class com.google.android.gms.ads.AdView
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at android.view.LayoutInflater.createView(LayoutInflater.java:633)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:743)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:806)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at android.view.LayoutInflater.inflate(LayoutInflater.java:504)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at android.view.LayoutInflater.inflate(LayoutInflater.java:414)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at android.view.LayoutInflater.inflate(LayoutInflater.java:365)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:378)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at android.app.Activity.setContentView(Activity.java:2145)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at com.jd.agecalculator.MainActivity.onCreate(MainActivity.java:30)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at android.app.Activity.performCreate(Activity.java:5990)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    ... 10 more
    03-30 01:21:20.290: E/AndroidRuntime(23904): Caused by: java.lang.reflect.InvocationTargetException
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at java.lang.reflect.Constructor.newInstance(Native Method)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at java.lang.reflect.Constructor.newInstance(Constructor.java:288)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at android.view.LayoutInflater.createView(LayoutInflater.java:607)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    ... 21 more
    03-30 01:21:20.290: E/AndroidRuntime(23904): Caused by: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/google/android/gms/R$styleable;
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at com.google.android.gms.ads.internal.client.zzk.<init>(Unknown Source)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at com.google.android.gms.ads.internal.client.zzab.<init>(Unknown Source)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at com.google.android.gms.ads.internal.client.zzab.<init>(Unknown Source)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at com.google.android.gms.ads.internal.client.zzab.<init>(Unknown Source)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at com.google.android.gms.ads.BaseAdView.<init>(Unknown Source)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at com.google.android.gms.ads.AdView.<init>(Unknown Source)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    ... 24 more
    03-30 01:21:20.290: E/AndroidRuntime(23904): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.R$styleable" on path: DexPathList[[zip file "/data/app/com.jd.agecalculator-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
    03-30 01:21:20.290: E/AndroidRuntime(23904):    ... 30 more
    03-30 01:21:20.290: E/AndroidRuntime(23904):    Suppressed: java.lang.ClassNotFoundException: com.google.android.gms.R$styleable
    03-30 01:21:20.290: E/AndroidRuntime(23904):        at java.lang.Class.classForName(Native Method)
    03-30 01:21:20.290: E/AndroidRuntime(23904):        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
    03-30 01:21:20.290: E/AndroidRuntime(23904):        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
    03-30 01:21:20.290: E/AndroidRuntime(23904):        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
    03-30 01:21:20.290: E/AndroidRuntime(23904):        ... 31 more
    03-30 01:21:20.290: E/AndroidRuntime(23904):    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available


**From here are my sources:**

**AdnroidManifest.xml:**


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

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="21" />

    <!-- Google AdMob Permission -->
    <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="@android:style/Theme.NoTitleBar" >
        <!-- Google AdMob -->
        <meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
        <activity
            android:name=".IntroActivity"
            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=".MainActivity"
            android:label="@string/title_activity_intro" >
        </activity>
        <activity android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
            android:theme="@android:style/Theme.Translucent" />
    </application>
</manifest>

**MainActivity.java:**


    public class MainActivity extends Activity {
    EditText name, birthYear, birthMonth, birthDay, testAgeYear, testAgeMonth;
    TextView ageResultYear, ageResultMonth, ageResultDay, testResult;
    UserInfo userInfo = new UserInfo();

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

        /* Google AdMob */
        mAdView = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);
    @Override
    protected void onPause() {
        mAdView.pause();
        super.onPause();
    }

    @Override
    protected void onResume() {
        super.onResume();
        mAdView.resume();
    }

**activity_main.xml**


    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:ads="http://schemas.android.com/apk/res-auto"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/background"
        android:orientation="vertical">

        <com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            ads:adSize="BANNER"
            ads:adUnitId="@string/banner_ad_unit_id">
        </com.google.android.gms.ads.AdView>

0 个答案:

没有答案