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

时间:2014-07-16 21:35:10

标签: android admob

我是android和admob的新手。 我下载了sdk ...导入的播放服务库并完成了在sdk文档上编写的所有内容。 但是当我添加xml片段时:

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

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

com.google.android.gms.ads.AdView无法实例化。 我知道这个问题早些时候被提出过,但对我来说都没有用。 上述错误的错误日志:

    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)

此外,我已经切换到来自kepler的eclipse luna这是否会导致问题? 我的xml文件:

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

我还尝试添加banner programicaly。我收到了以下错误:

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

修改 我搜索了上面的错误,我在这里找到了解决方案https://stackoverflow.com/a/14004090/2647040

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

1 个答案:

答案 0 :(得分:2)

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

如果你有旧的admob sdk以及Google Play服务,那么从你的libs文件夹中删除旧的admob sdk并清理你的项目它应该解决这个bug。