在Android开发中使用Admob会破坏示例代码

时间:2012-09-16 07:47:32

标签: android admob

我只想在我的Android应用程序中尝试使用Admob的基础知识,但由于某种原因,即使示例代码也会崩溃我的设备和模拟器。我按照https://developers.google.com/mobile-ads-sdk/docs/上的说明操作,并没有解决我的问题。据我所知,一切都包含正确,我已经将jar文件添加到构建路径等等。但由于某种原因,我总是得到如下错误:

09-16 00:36:11.855: E/AndroidRuntime(305): FATAL EXCEPTION: main
09-16 00:36:11.855: E/AndroidRuntime(305): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.example.ads.xml/com.google.example.ads.xml.BannerSample}: android.view.InflateException: Binary XML file line #10: Error inflating class com.google.ads.AdView
09-16 00:36:11.855: E/AndroidRuntime(305):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
09-16 00:36:11.855: E/AndroidRuntime(305):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-16 00:36:11.855: E/AndroidRuntime(305):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-16 00:36:11.855: E/AndroidRuntime(305):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-16 00:36:11.855: E/AndroidRuntime(305):  at android.os.Handler.dispatchMessage(Handler.java:99)
09-16 00:36:11.855: E/AndroidRuntime(305):  at android.os.Looper.loop(Looper.java:123)
09-16 00:36:11.855: E/AndroidRuntime(305):  at android.app.ActivityThread.main(ActivityThread.java:4627)
09-16 00:36:11.855: E/AndroidRuntime(305):  at java.lang.reflect.Method.invokeNative(Native Method)
09-16 00:36:11.855: E/AndroidRuntime(305):  at java.lang.reflect.Method.invoke(Method.java:521)
09-16 00:36:11.855: E/AndroidRuntime(305):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-16 00:36:11.855: E/AndroidRuntime(305):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-16 00:36:11.855: E/AndroidRuntime(305):  at dalvik.system.NativeStart.main(Native Method)
09-16 00:36:11.855: E/AndroidRuntime(305): Caused by: android.view.InflateException: Binary XML file line #10: Error inflating class com.google.ads.AdView
09-16 00:36:11.855: E/AndroidRuntime(305):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
09-16 00:36:11.855: E/AndroidRuntime(305):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
09-16 00:36:11.855: E/AndroidRuntime(305):  at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
09-16 00:36:11.855: E/AndroidRuntime(305):  at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
09-16 00:36:11.855: E/AndroidRuntime(305):  at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
09-16 00:36:11.855: E/AndroidRuntime(305):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
09-16 00:36:11.855: E/AndroidRuntime(305):  at android.app.Activity.setContentView(Activity.java:1647)
09-16 00:36:11.855: E/AndroidRuntime(305):  at com.google.example.ads.xml.BannerSample.onCreate(BannerSample.java:14)
09-16 00:36:11.855: E/AndroidRuntime(305):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-16 00:36:11.855: E/AndroidRuntime(305):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-16 00:36:11.855: E/AndroidRuntime(305):  ... 11 more
09-16 00:36:11.855: E/AndroidRuntime(305): Caused by: java.lang.ClassNotFoundException: com.google.ads.AdView in loader dalvik.system.PathClassLoader[/data/app/com.google.example.ads.xml-2.apk]
09-16 00:36:11.855: E/AndroidRuntime(305):  at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
09-16 00:36:11.855: E/AndroidRuntime(305):  at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
09-16 00:36:11.855: E/AndroidRuntime(305):  at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
09-16 00:36:11.855: E/AndroidRuntime(305):  at android.view.LayoutInflater.createView(LayoutInflater.java:466)
09-16 00:36:11.855: E/AndroidRuntime(305):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
09-16 00:36:11.855: E/AndroidRuntime(305):  ... 20 more

非常感谢任何帮助。谢谢!

2 个答案:

答案 0 :(得分:2)

您是否已将jar文件放入libs folder?。如果没有创建名为libs的新文件夹并将jar文件复制粘贴到其中,则通过右键单击它将其添加到构建路径并选择构建路径选项和添加到构建路径。也不要在Dialog中使用adview。这可能会导致问题。如需更多帮助,请按照分步指南https://developers.google.com/mobile-ads-sdk/docs/进行操作。

Answer-

但是将你的jar文件放在libs文件夹中这是一个很好的做法,以便它可以正确管理,我经历过一段时间,如果我不把我的jar放在libs文件夹中,它给我的课程没有找到异常,那就是为什么我建议你这样做。这次你可能没有任何问题,但大部分时间都会引起问题

答案 1 :(得分:1)

所以看起来我掩饰了一步。我的错。我忘了检查订单/导出选项卡中的jar。