在Android上仍然有AdMob问题

时间:2012-07-09 17:07:54

标签: java android admob manifest

我已阅读了大约24篇文章,并通过Google文档和我的代码,因为它只是给了我一个强制关闭框。这是我的代码

清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ndai.funnys"
    android:versionCode="1" 
    android:versionName="1.0" >
    <uses-sdk android:minSdkVersion="8"  
        android:targetSdkVersion="15" />
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:name=".GuysFunnysActivity"
            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.ads.AdActivity"
    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
    </application>
</manifest>

main.xml中

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout  android:id="@+id/LinearLayout01"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <com.google.ads.AdView android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adUnitId="a14ffb06b21e68e"
        ads:adSize="BANNER"
        ads:testDevices="TEST_EMULATOR, 12345678901234567890123456789012"
        ads:loadAdOnCreate="true"/>
</LinearLayout>

JAVA

package com.ndai.funnys;

import java.io.InputStream;
import java.net.URL;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.google.ads.*;

public class GuysFunnysActivity extends Activity 
{
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}

我做错了什么?这正如我在其他网站上看到的那样。即使我使用了测试设备代码,我也尝试过非xml版本的相同问题。

logcat的

07-09 17:34:23.207: D/AndroidRuntime(729): Shutting down VM
07-09 17:34:23.207: W/dalvikvm(729): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
07-09 17:34:23.237: E/AndroidRuntime(729): FATAL EXCEPTION: main
07-09 17:34:23.237: E/AndroidRuntime(729): java.lang.RuntimeException: Unable to start activity ComponentInfo    {com.ndai.funnys/com.ndai.funnys.GuysFunnysActivity}: android.view.InflateException: Binary XML file line #8: Error inflating class com.google.ads.AdView
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.os.Handler.dispatchMessage(Handler.java:99)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.os.Looper.loop(Looper.java:123)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.app.ActivityThread.main(ActivityThread.java:4627)
07-09 17:34:23.237: E/AndroidRuntime(729):  at java.lang.reflect.Method.invokeNative(Native Method)
07-09 17:34:23.237: E/AndroidRuntime(729):  at java.lang.reflect.Method.invoke(Method.java:521)
07-09 17:34:23.237: E/AndroidRuntime(729):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-09 17:34:23.237: E/AndroidRuntime(729):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-09 17:34:23.237: E/AndroidRuntime(729):  at dalvik.system.NativeStart.main(Native Method)
07-09 17:34:23.237: E/AndroidRuntime(729): Caused by: android.view.InflateException: Binary XML file line #8: Error inflating class com.google.ads.AdView
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
07-09 17:34:23.237: E/AndroidRuntime(729):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.app.Activity.setContentView(Activity.java:1647)
07-09 17:34:23.237: E/AndroidRuntime(729):  at com.ndai.funnys.GuysFunnysActivity.onCreate(GuysFunnysActivity.java:20)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-09 17:34:23.237: E/AndroidRuntime(729):  ... 11 more
07-09 17:34:23.237: E/AndroidRuntime(729): Caused by: java.lang.ClassNotFoundException: com.google.ads.AdView in loader dalvik.system.PathClassLoader    [/data/app/com.ndai.funnys-2.apk]
07-09 17:34:23.237: E/AndroidRuntime(729):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
07-09 17:34:23.237: E/AndroidRuntime(729):  at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
07-09 17:34:23.237: E/AndroidRuntime(729):  at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.view.LayoutInflater.createView(LayoutInflater.java:466)
07-09 17:34:23.237: E/AndroidRuntime(729):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
07-09 17:34:23.237: E/AndroidRuntime(729):  ... 20 more

1 个答案:

答案 0 :(得分:1)

在Eclipse中,必须将所有jar添加到libs /或专门导出Order And Export的{​​{1}}选项卡中。否则,jar将不会捆绑到已编译的代码中,并且在引用jar文件时,您的应用程序将在运行时失败。