简体   繁体   中英

Failed to instantiate com.google.android.gms.common.SignInButton

First off, I am sorry to ask this question, as this has been asked by others several months and years back. I could however not find a fix for this.

I was following the Google Play Services tutorial to include the G+ Sign-In button in one of my XML layouts for one of my apps that uses Google Play Services. Meaning adding the following snipped to my layout:

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

I however am unable to do so, because eclipse always tells me :

The following classes could not be instantiated: - com.google.android.gms.common.SignInButton

The exception stack trace looks like this:

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)

I tried every possible solution I could find but nothing worked.

For now I am just adding the Sign-In button programatically, and it works as you expect it would. But I have no idea why I can't simply add the button via XML. The Google Play Services are set as a library currently and my project is using it as one.

The beginning of the stack trace reads:

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

Do I interpret this right when I think the button is unable to find and/or get the app context when I try to add it via XML, and that might be the error here? In that case merging the Google Play Services lib with my project should resolve it, no? But this would bloat the project unnecessarily. Any alternatives?

Only clean the project and closes Eclipse. Then you should reopen Elipse and the button should work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM