使用AdView类时出现此错误。问题是什么?我试过Order&导出,关闭和重新打开Eclipse,以及我在网上可以找到的几乎所有建议。什么都没有,所以我在这里。
XML文件的第14行是:
<com.google.android.gms.ads.AdView
以下是包含AdView的活动的XML文件(那不是我的实际ID):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads= "http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:orientation="horizontal"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".SearchActivity" >
<com.google.android.gms.ads.AdView
android:id = "@+id/adView"
xmlns:ads="http://schemas.android.com/apk/libs/com.google.ads"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
ads:adSize="MEDIUM_RECTANGLE"
ads:adUnitId="pub-1234567891234567" >
</com.google.android.gms.ads.AdView>
<ListView
android:id="@+id/list"
android:layout_width="248dp"
android:layout_height="392dp"
android:layout_marginTop="30dp" >
</ListView>
<TextView
android:layout_width="200dp"
android:layout_height="18dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Search results"/>
</RelativeLayout>
这是logcat:
05-18 16:00:00.233: I/Process(6997): Sending signal. PID: 6997 SIG: 9
05-18 16:03:29.038: I/dalvikvm(7141): Could not find method android.content.pm.PackageManager.getActivityLogo, referenced from method android.support.v7.internal.widget.ActionBarView.<init>
05-18 16:03:29.038: W/dalvikvm(7141): VFY: unable to resolve virtual method 511: Landroid/content/pm/PackageManager;.getActivityLogo (Landroid/content/ComponentName;)Landroid/graphics/drawable/Drawable;
05-18 16:03:29.038: D/dalvikvm(7141): VFY: replacing opcode 0x6e at 0x008b
05-18 16:03:29.038: I/dalvikvm(7141): Could not find method android.content.pm.ApplicationInfo.loadLogo, referenced from method android.support.v7.internal.widget.ActionBarView.<init>
05-18 16:03:29.038: W/dalvikvm(7141): VFY: unable to resolve virtual method 504: Landroid/content/pm/ApplicationInfo;.loadLogo (Landroid/content/pm/PackageManager;)Landroid/graphics/drawable/Drawable;
05-18 16:03:29.038: D/dalvikvm(7141): VFY: replacing opcode 0x6e at 0x0099
05-18 16:03:29.042: D/dalvikvm(7141): VFY: dead code 0x008e-0092 in Landroid/support/v7/internal/widget/ActionBarView;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;)V
05-18 16:03:29.042: D/dalvikvm(7141): VFY: dead code 0x009c-00a0 in Landroid/support/v7/internal/widget/ActionBarView;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;)V
05-18 16:03:29.116: D/skia(7141): purging 6K from font cache [1 entries]
05-18 16:03:29.116: D/SKIA_FONT(7141): stored typeface in slot 0
05-18 16:03:29.116: D/SKIA_FONT(7141): SKIA_FONT fontfile: /data/data/com.android.settings/app_fonts/default/DroidSans.ttf
05-18 16:03:29.116: D/SKIA_FONT(7141): SKIA_FONT fontfile: /data/data/com.android.settings/app_fonts/default/DroidSans.ttf
05-18 16:03:29.116: D/SKIA_FONT(7141): load_system_fonts(), name = Droid Sans, style = 0, uniqueID = 13
05-18 16:03:29.120: D/SKIA_FONT(7141): SKIA_FONT fontfile: /data/data/com.android.settings/app_fonts/default/DroidSans-Bold.ttf
05-18 16:03:29.120: D/SKIA_FONT(7141): SKIA_FONT fontfile: /data/data/com.android.settings/app_fonts/default/DroidSans-Bold.ttf
05-18 16:03:29.120: D/SKIA_FONT(7141): load_system_fonts(), name = Droid Sans, style = 1, uniqueID = 14
05-18 16:03:29.128: D/SKIA_FONT(7141): load_system_fonts(), name = Droid Serif, style = 0, uniqueID = 15
05-18 16:03:29.135: D/SKIA_FONT(7141): load_system_fonts(), name = Droid Serif, style = 1, uniqueID = 16
05-18 16:03:29.143: D/SKIA_FONT(7141): load_system_fonts(), name = Droid Serif, style = 2, uniqueID = 17
05-18 16:03:29.167: D/SKIA_FONT(7141): load_system_fonts(), name = Droid Serif, style = 3, uniqueID = 18
05-18 16:03:29.171: D/SKIA_FONT(7141): load_system_fonts(), name = Droid Sans Mono, style = 0, uniqueID = 19
05-18 16:03:29.171: D/SKIA_FONT(7141): load_system_fonts(), name = Droid Sans Arabic, style = 0, uniqueID = 20
05-18 16:03:29.171: D/SKIA_FONT(7141): load_system_fonts(), name = Droid Sans Hebrew, style = 0, uniqueID = 21
05-18 16:03:29.175: D/SKIA_FONT(7141): load_system_fonts(), name = Droid Sans Thai, style = 0, uniqueID = 22
05-18 16:03:29.178: D/SKIA_FONT(7141): load_system_fonts(), name = Droid Sans, style = 0, uniqueID = 23
05-18 16:03:29.198: D/SKIA_FONT(7141): load_system_fonts(), name = Droid Sans Fallback, style = 0, uniqueID = 24
05-18 16:03:29.198: D/SKIA_FONT(7141): load_system_fonts(), oldSansUID = 1, newSansUID = 13
05-18 16:03:29.198: D/SKIA_FONT(7141): load_system_fonts(), oldSansBoldUID = 2, newSansBoldUID = 14
05-18 16:03:32.210: D/SearchDialog(7141): launching Intent { act=android.intent.action.SEARCH flg=0x10000000 cmp=com.example.activity2/.SearchActivity (has extras) }
05-18 16:03:32.214: I/SearchDialog(7141): Starting (as ourselves) #Intent;action=android.intent.action.SEARCH;launchFlags=0x10000000;component=com.example.activity2/.SearchActivity;S.query=J;S.user_query=J;end
05-18 16:03:32.288: I/System.out(7141): file is /mnt/sdcard
05-18 16:03:32.292: W/dalvikvm(7141): VFY: unable to resolve static field 4641 (AdsAttrs) in Lcom/google/android/gms/R$styleable;
05-18 16:03:32.292: D/dalvikvm(7141): VFY: replacing opcode 0x62 at 0x0009
05-18 16:03:32.292: D/dalvikvm(7141): VFY: dead code 0x000b-0068 in Lcom/google/android/gms/internal/ao;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;)V
05-18 16:03:32.303: D/AndroidRuntime(7141): Shutting down VM
05-18 16:03:32.303: W/dalvikvm(7141): threadid=1: thread exiting with uncaught exception (group=0x4001d7d0)
05-18 16:03:32.339: D/dalvikvm(7141): GC_FOR_MALLOC freed 3272 objects / 222072 bytes in 30ms
05-18 16:03:32.358: E/AndroidRuntime(7141): FATAL EXCEPTION: main
05-18 16:03:32.358: E/AndroidRuntime(7141): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.activity2/com.example.activity2.SearchActivity}: android.view.InflateException: Binary XML file line #14: Error inflating class com.google.android.gms.ads.AdView
05-18 16:03:32.358: E/AndroidRuntime(7141): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
05-18 16:03:32.358: E/AndroidRuntime(7141): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
05-18 16:03:32.358: E/AndroidRuntime(7141): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
05-18 16:03:32.358: E/AndroidRuntime(7141): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
05-18 16:03:32.358: E/AndroidRuntime(7141): at android.os.Handler.dispatchMessage(Handler.java:99)
05-18 16:03:32.358: E/AndroidRuntime(7141): at android.os.Looper.loop(Looper.java:123)
05-18 16:03:32.358: E/AndroidRuntime(7141): at android.app.ActivityThread.main(ActivityThread.java:4627)
05-18 16:03:32.358: E/AndroidRuntime(7141): at java.lang.reflect.Method.invokeNative(Native Method)
05-18 16:03:32.358: E/AndroidRuntime(7141): at java.lang.reflect.Method.invoke(Method.java:521)
05-18 16:03:32.358: E/AndroidRuntime(7141): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
05-18 16:03:32.358: E/AndroidRuntime(7141): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
05-18 16:03:32.358: E/AndroidRuntime(7141): at dalvik.system.NativeStart.main(Native Method)
05-18 16:03:32.358: E/AndroidRuntime(7141): Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class com.google.android.gms.ads.AdView
05-18 16:03:32.358: E/AndroidRuntime(7141): at android.view.LayoutInflater.createView(LayoutInflater.java:513)
05-18 16:03:32.358: E/AndroidRuntime(7141): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
05-18 16:03:32.358: E/AndroidRuntime(7141): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
05-18 16:03:32.358: E/AndroidRuntime(7141): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
05-18 16:03:32.358: E/AndroidRuntime(7141): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
05-18 16:03:32.358: E/AndroidRuntime(7141): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
05-18 16:03:32.358: E/AndroidRuntime(7141): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:200)
05-18 16:03:32.358: E/AndroidRuntime(7141): at android.app.Activity.setContentView(Activity.java:1647)
05-18 16:03:32.358: E/AndroidRuntime(7141): at com.example.activity2.SearchActivity.onCreate(SearchActivity.java:76)
05-18 16:03:32.358: E/AndroidRuntime(7141): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-18 16:03:32.358: E/AndroidRuntime(7141): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
05-18 16:03:32.358: E/AndroidRuntime(7141): ... 11 more
05-18 16:03:32.358: E/AndroidRuntime(7141): Caused by: java.lang.reflect.InvocationTargetException
05-18 16:03:32.358: E/AndroidRuntime(7141): at com.google.android.gms.ads.AdView.<init>(Unknown Source)
05-18 16:03:32.358: E/AndroidRuntime(7141): at java.lang.reflect.Constructor.constructNative(Native Method)
05-18 16:03:32.358: E/AndroidRuntime(7141): at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
05-18 16:03:32.358: E/AndroidRuntime(7141): at android.view.LayoutInflater.createView(LayoutInflater.java:500)
05-18 16:03:32.358: E/AndroidRuntime(7141): ... 21 more
05-18 16:03:32.358: E/AndroidRuntime(7141): Caused by: java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
05-18 16:03:32.358: E/AndroidRuntime(7141): at com.google.android.gms.internal.ao.<init>(Unknown Source)
05-18 16:03:32.358: E/AndroidRuntime(7141): at com.google.android.gms.internal.au.<init>(Unknown Source)
05-18 16:03:32.358: E/AndroidRuntime(7141): at com.google.android.gms.internal.au.<init>(Unknown Source)
05-18 16:03:32.358: E/AndroidRuntime(7141): ... 25 more
05-18 16:08:37.901: I/Process(7141): Sending signal. PID: 7141 SIG: 9
有什么建议吗?一直试图让这个非常简单的AdView全天工作。谢谢。
答案 0 :(得分:-1)
替换此行:
xmlns:ads="http://schemas.android.com/apk/libs/com.google.ads"
与
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
命名空间位于lib名称而不是libs。
并确保您在build.gradle中使用Google Play服务
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services:7.0.0'
}
答案 1 :(得分:-3)
不要将google-play-services.jar
放在/libs/
文件夹中。相反,请参考项目中的Google Play服务库。
将库导入工作区。如果您通过sdk管理器下载,您将在sdk/extras/google/..
中找到它。然后通过右键单击您的项目参考=&gt;选择属性=&gt; Android =&gt;添加
首先在您的应用中正确附加Google Play服务,然后在布局xml文件中添加xml-name-space。
xmlns:ads="http://schemas.android.com/apk/res-auto"
然后使用此
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="center"
ads:adSize="BANNER"
ads:adUnitId="Your AddUnitID" />
在manifiest.xml
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:screenOrientation="portrait" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
并添加权限
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />