Reputation: 2110
I'm just trying to get the basics down of using Admob in my android apps, but for some reason, even the example code crashes my device and emulator. I followed the instructions on https://developers.google.com/mobile-ads-sdk/docs/ and it didn't fix my problem. As far as I can see, everything is included properly, I've added the jar file to the build path, etc etc. But for some reason, I always get errors like the following:
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
Any help would be greatly appreciated. Thanks!
Upvotes: 0
Views: 1008
Reputation: 1986
Have you put jar file in libs folder
?.If Not create a new folder named libs and copy paste the jar file in it then add it to build path by right click on it and choose build path option and the add to build path.Also Do not use adview
in Dialog.It may cause problem.For more help just follow the step by step guide https://developers.google.com/mobile-ads-sdk/docs/ .
Answer-
But it is good practice to put your jar file in libs folder so that it can be managed properly and I have experienced some time when if i do not put my jar in the libs folder it gives me class not found exception OK that's why I suggest you to do the same. this time you may not have any problem but most of the time It cause problem
Upvotes: 2
Reputation: 2110
So it looks like I glossed over a step. My Bad. I forgot to check the jar in the order/export tab.
Upvotes: 1