问题
I am trying to show a adview in my android application, but it shows an InflateException. This terminates the app and I cannot do anything.
Here is my logcat -
05-06 14:09:09.428: E/AndroidRuntime(928): FATAL EXCEPTION: main
05-06 14:09:09.428: E/AndroidRuntime(928): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kodspider.parkon/com.kodspider.parkon.HomeActivity}: android.view.InflateException: Binary XML file line #18: Error inflating class com.google.ads.AdView
05-06 14:09:09.428: E/AndroidRuntime(928): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.os.Handler.dispatchMessage(Handler.java:99)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.os.Looper.loop(Looper.java:137)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.app.ActivityThread.main(ActivityThread.java:5039)
05-06 14:09:09.428: E/AndroidRuntime(928): at java.lang.reflect.Method.invokeNative(Native Method)
05-06 14:09:09.428: E/AndroidRuntime(928): at java.lang.reflect.Method.invoke(Method.java:511)
05-06 14:09:09.428: E/AndroidRuntime(928): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-06 14:09:09.428: E/AndroidRuntime(928): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-06 14:09:09.428: E/AndroidRuntime(928): at dalvik.system.NativeStart.main(Native Method)
05-06 14:09:09.428: E/AndroidRuntime(928): Caused by: android.view.InflateException: Binary XML file line #18: Error inflating class com.google.ads.AdView
05-06 14:09:09.428: E/AndroidRuntime(928): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:698)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-06 14:09:09.428: E/AndroidRuntime(928): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:270)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.app.Activity.setContentView(Activity.java:1881)
05-06 14:09:09.428: E/AndroidRuntime(928): at com.kodspider.parkon.HomeActivity.onCreate(HomeActivity.java:31)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.app.Activity.performCreate(Activity.java:5104)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-06 14:09:09.428: E/AndroidRuntime(928): ... 11 more
05-06 14:09:09.428: E/AndroidRuntime(928): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.ads.AdView" on path: /system/framework/com.google.android.maps.jar:/data/app/com.kodspider.parkon-2.apk
05-06 14:09:09.428: E/AndroidRuntime(928): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:65)
05-06 14:09:09.428: E/AndroidRuntime(928): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
05-06 14:09:09.428: E/AndroidRuntime(928): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.view.LayoutInflater.createView(LayoutInflater.java:552)
05-06 14:09:09.428: E/AndroidRuntime(928): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:687)
05-06 14:09:09.428: E/AndroidRuntime(928): ... 22 more
回答1:
You need to put the admob jar into the libs folder of your project.
回答2:
The same error appears to me and i solved with few simple steps.
You need to remove the appcombat dependency from your project. For removing right click your project->android->remove app combat and make sure you have selected android 4.2.2
And then import the google admob jar into your project.
来源:https://stackoverflow.com/questions/16400785/error-inflating-class-com-google-ads-adview-inflateexception