com.google.android.gms.ads.AdView 无法实例化

Posted

技术标签:

【中文标题】com.google.android.gms.ads.AdView 无法实例化【英文标题】:com.google.android.gms.ads.AdView failed to instantiate 【发布时间】:2014-07-16 21:35:09 【问题描述】:

我是 android 和 admob 的新手。 我下载了 sdk ......导入了 play 服务库并完成了在 sdk 文档上写的所有事情。 但是当我添加 xml sn-p:

<com.google.android.gms.ads.AdView android:id="@+id/adView"
 android:layout_
 android:layout_
 ads:adUnitId="MY_AD_UNIT_ID"
 ads:adSize="BANNER"/>

我在错误日志中收到以下消息

。 我知道之前有人问过这个问题,但没有一个对我有用。 上述错误的错误日志:

    eclipse.buildId=4.4.0.I20140606-1215
    java.version=1.8.0_05
    java.vendor=Oracle Corporation
    BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US
    Framework arguments:  -product org.eclipse.epp.package.standard.product
    Command-line arguments:  -os win32 -ws win32 -arch x86 -product org.eclipse.epp.package.standard.product
    com.android.ide.eclipse.adt
    Error
    Fri Jul 18 00:43:46 IST 2014
    com.google.android.gms.ads.AdView failed to instantiate.
    java.lang.VerifyError: Expecting a stackmap frame at branch target 57
    Exception Details:
    Location:
    com/google/android/gms/ads/AdView.onMeasure(II)V @20: ifnull
    Reason:
    Expected stackmap frame at this location.
    Bytecode:
0000000: 033e 0336 042a 03b6 0015 3a05 2ab6 0014
0000010: 3a06 1905 c600 2519 05b6 000b 1008 9f00
0000020: 1b2a 1905 1b1c b600 1919 05b6 000a 3e19
0000030: 05b6 0009 3604 a700 1f19 06c6 001a 2ab6
0000040: 0016 3a07 1906 1907 b600 133e 1906 1907
0000050: b600 1236 041d 2ab6 0018 b800 2a3e 1504
0000060: 2ab6 0017 b800 2a36 042a 1d1b b800 0d15
0000070: 041c b800 0db6 001a b1                 
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getConstructor(Unknown Source)
at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.instantiateClass(ProjectCallback.java:363)
at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:190)
at android.view.BridgeInflater.loadCustomView(BridgeInflater.java:207)
at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:132)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:802)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:778)
at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:805)
at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:64)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:778)
at android.view.LayoutInflater.inflate(LayoutInflater.java:500)
at android.view.LayoutInflater.inflate(LayoutInflater.java:381)
at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:395)
at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:329)
at com.android.ide.common.rendering.LayoutLibrary.createSession(LayoutLibrary.java:332)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.RenderService.createRenderSession(RenderService.java:517)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.renderWithBridge(GraphicalEditorPart.java:1584)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.recomputeLayout(GraphicalEditorPart.java:1309)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.changed(GraphicalEditorPart.java:725)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart.onTargetChange(GraphicalEditorPart.java:1196)
at com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditorDelegate.onDescriptorsChanged(LayoutEditorDelegate.java:916)
at com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditorDelegate.delegateInitUiRootNode(LayoutEditorDelegate.java:835)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart$TargetListener.updateEditor(GraphicalEditorPart.java:953)
at com.android.ide.eclipse.adt.internal.editors.layout.gle2.GraphicalEditorPart$TargetListener.onProjectTargetChange(GraphicalEditorPart.java:909)
at com.android.ide.eclipse.adt.AdtPlugin$10.run(AdtPlugin.java:1722)
at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:136)
at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4147)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3764)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1151)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1032)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:148)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:636)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:579)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:135)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:382)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:236)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:648)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:603)
at org.eclipse.equinox.launcher.Main.run(Main.java:1465)

另外,我已经从开普勒切换到 Eclipse Luna,这会导致问题吗? 我的 xml 文件:

<RelativeLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_
android:layout_
 android:id="@+id/mainScreen"
 >
 <LinearLayout 
     android:layout_
     android:layout_
     android:layout_alignParentBottom="true">
      <com.google.android.gms.ads.AdView android:id="@+id/adView"
                     android:layout_
                     android:layout_
                     ads:adUnitId="_id"
                     ads:adSize="BANNER"/>   
</LinearLayout>
</RelativeLayout>

我也尝试以编程方式添加横幅。我收到以下错误:

描述资源路径位置类型 转换为 Dalvik 格式失败:无法执行 dex:多个 dex 文件定义 Lcom/google/ads/AdRequest$ErrorCode; myApp 未知的 Android 打包问题

编辑 我搜索了上述错误并在这里找到了解决方案https://***.com/a/14004090/2647040

现在它在以编程方式添加横幅时不会显示任何错误。 通过xml添加横幅时确实显示相同的错误错误,但现在在模拟器上显示广告。

【问题讨论】:

您正在测试的设备是否安装了 Google Play 服务? 是的,我确实安装了它。 【参考方案1】:

看起来您可能有两个 Admob 类的副本。当您尝试使用新的 Google Play 服务类时,您可能仍将旧的 admob sdk 作为应用程序库。

如果您有旧的 admob sdk 以及 Google Play 服务,则从您的 libs 文件夹中删除旧的 admob sdk 并清理您的项目,它应该可以解决错误。

【讨论】:

以上是关于com.google.android.gms.ads.AdView 无法实例化的主要内容,如果未能解决你的问题,请参考以下文章