我将admob广告添加到我的应用程序。它显示没有错误,但不幸的是,在模拟器显示中运行项目后,应用程序已停止。我不知道为什么请帮助我。 我的布局是:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/main"
android:fitsSystemWindows="true"
android:gravity="bottom|center"
android:orientation="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true" >
<Button
android:id="@+id/nextButton"
android:layout_width="98dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="191dp"
android:background="@drawable/button"
android:gravity="center"
android:text="@string/next" />
<com.google.ads.AdView
android:id="@+id/ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adUnitId="xxxxxxxxxxxx"
ads:adSize="BANNER"
ads:loadAdOnCreate="true"
android:layout_gravity="center"
android:layout_margin="10dp">
</com.google.ads.AdView>
</RelativeLayout>
`
我的activity.java是:
public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViewById(R.id.nextButton).setOnClickListener(new handleButton());
}
class handleButton implements OnClickListener {
public void onClick(View v) {
Intent intent = new Intent(Main.this, Screen2.class);
startActivity(intent);
}
}
}
我的Logcat中的错误是:
01-06 19:39:20.250: E/AndroidRuntime(1551): FATAL EXCEPTION: main
01-06 19:39:20.250: E/AndroidRuntime(1551): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.vaibgi.candytricks/com.vaibgi.candytricks.Main}: android.view.InflateException: Binary XML file line #24: Error inflating class com.google.ads.AdView
01-06 19:39:20.250: E/AndroidRuntime(1551): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
01-06 19:39:20.250: E/AndroidRuntime(1551): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
01-06 19:39:20.250: E/AndroidRuntime(1551): at android.app.ActivityThread.access$600(ActivityThread.java:141)
01-06 19:39:20.250: E/AndroidRuntime(1551): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
01-06 19:39:20.250: E/AndroidRuntime(1551): at android.os.Handler.dispatchMessage(Handler.java:99)
01-06 19:39:20.250: E/AndroidRuntime(1551): at android.os.Looper.loop(Looper.java:137)
01-06 19:39:20.250: E/AndroidRuntime(1551): at android.app.ActivityThread.main(ActivityThread.java:5039)
01-06 19:39:20.250: E/AndroidRuntime(1551): at java.lang.reflect.Method.invokeNative(Native Method)
01-06 19:39:20.250: E/AndroidRuntime(1551): at java.lang.reflect.Method.invoke(Method.java:511)
01-06 19:39:20.250: E/AndroidRuntime(1551): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
01-06 19:39:20.250: E/AndroidRuntime(1551): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
01-06 19:39:20.250: E/AndroidRuntime(1551): at dalvik.system.NativeStart.main(Native Method)
01-06 19:39:20.250: E/AndroidRuntime(1551): Caused by: android.view.InflateException: Binary XML file line #24: Error inflating class com.google.ads.AdView
01-06 19:39:20.250: E/AndroidRuntime(1551): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
01-06 19:39:20.250: E/AndroidRuntime(1551): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
01-06 19:39:20.250: E/AndroidRuntime(1551): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
01-06 19:39:20.250: E/AndroidRuntime(1551): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-06 19:39:20.250: E/AndroidRuntime(1551): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
01-06 19:39:20.250: E/AndroidRuntime(1551): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
01-06 19:39:20.250: E/AndroidRuntime(1551): at android.app.Activity.setContentView(Activity.java:1881)
01-06 19:39:20.250: E/AndroidRuntime(1551): at com.vaibgi.candytricks.Main.onCreate(Main.java:17)
01-06 19:39:20.250: E/AndroidRuntime(1551): at android.app.Activity.performCreate(Activity.java:5104)
01-06 19:39:20.250: E/AndroidRuntime(1551): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
01-06 19:39:20.250: E/AndroidRuntime(1551): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
01-06 19:39:20.250: E/AndroidRuntime(1551): ... 11 more
01-06 19:39:20.250: E/AndroidRuntime(1551): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.ads.AdView" on path: /data/app/com.vaibgi.candytricks-1.apk
01-06 19:39:20.250: E/AndroidRuntime(1551): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
01-06 19:39:20.250: E/AndroidRuntime(1551): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
01-06 19:39:20.250: E/AndroidRuntime(1551): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
01-06 19:39:20.250: E/AndroidRuntime(1551): at android.view.LayoutInflater.createView(LayoutInflater.java:552)
01-06 19:39:20.250: E/AndroidRuntime(1551): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
01-06 19:39:20.250: E/AndroidRuntime(1551): ... 21 more
我想要纠正什么?请帮助我的朋友