无法实例化com.google.android.gms.common.SignInButton

时间:2014-11-15 13:21:28

标签: java android xml eclipse google-play-services

首先,我很遗憾地提出这个问题,因为其他几个月和几年前已经有人问过这个问题。但是,我无法找到解决方案。

我正在关注Google Play服务教程,在我的一个XML布局中包含G +登录按钮,用于我的一个使用Google Play服务的应用。意味着将以下内容添加到我的布局:

        <com.google.android.gms.common.SignInButton
            android:id="@+id/sign_in_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

但我无法这样做,因为eclipse总是告诉我:

  

无法实例化以下类:    - com.google.android.gms.common.SignInButton

异常堆栈跟踪如下所示:

java.lang.VerifyError: Expecting a stackmap frame at branch target 15
Exception Details:
  Location:
    com/google/android/gms/common/SignInButton.z(Landroid/content/Context;)V @4: ifnull
  Reason:
    Expected stackmap frame at this location.
  Bytecode:
    0000000: 2ab4 0016 c600 0b2a 2ab4 0016 b600 252a
    0000010: 2b2a b400 182a b400 15b8 0029 b500 16a7
    0000020: 001c 4d12 0512 04b8 001a 572a 2b2a b400
    0000030: 182a b400 15b8 0021 b500 162a 2ab4 0016
    0000040: b600 222a b400 162a b600 24b6 001b 2ab4
    0000050: 0016 2ab6 001c b1                      
  Exception Handler Table:
    bci [15, 31] => handler: 34

    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:367)
    at com.android.ide.eclipse.adt.internal.editors.layout.ProjectCallback.loadView(ProjectCallback.java:194)
    at com.android.layoutlib.bridge.android.BridgeInflater.loadCustomView(BridgeInflater.java:205)
    at com.android.layoutlib.bridge.android.BridgeInflater.createViewFromTag(BridgeInflater.java:133)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:296)
    at com.android.layoutlib.bridge.impl.RenderSessionImpl.inflate(RenderSessionImpl.java:279)
    at com.android.layoutlib.bridge.Bridge.createSession(Bridge.java:318)
    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.activated(GraphicalEditorPart.java:1066)
    at com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditorDelegate.delegatePageChange(LayoutEditorDelegate.java:686)
    at com.android.ide.eclipse.adt.internal.editors.common.CommonXmlEditor.pageChange(CommonXmlEditor.java:360)
    at org.eclipse.ui.part.MultiPageEditorPart$2.widgetSelected(MultiPageEditorPart.java:294)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4353)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1061)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1085)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1070)
    at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:782)
    at org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:3110)
    at org.eclipse.swt.custom.CTabFolder.onMouse(CTabFolder.java:1794)
    at org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:283)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4353)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1061)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4172)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3761)
    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)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1438)

我尝试了所有可能找到的解决方案,但没有任何效果。

现在我只是以编程方式添加“登录”按钮,它可以按预期工作。但我不知道为什么我不能简单地通过XML添加按钮。 Google Play服务目前已设置为库,我的项目将其作为一个库使用。

堆栈跟踪的开头是:

Exception Details:
      Location:
        com/google/android/gms/common/SignInButton.z(Landroid/content/Context;)V @4: ifnull

当我尝试通过XML添加按钮时无法找到和/或获取应用程序上下文时,我是否正确解释了这一点,这可能是错误吗?在这种情况下,将Google Play服务lib与我的项目合并应解决它,不是吗?但这会使项目不必要地膨胀。任何替代方案?

1 个答案:

答案 0 :(得分:0)

仅清理项目并关闭Eclipse。然后你应该重新打开Elipse,按钮应该工作