我不知道我做错了什么,但我的 SignInButton for Google+ 不断出现以下错误
09-02 19:26:56.245 12537-12537/com.ferdiseegers.klantenbestand E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ferdiseegers.klantenbestand/com.ferdiseegers.klantenbestand.Activities.LoginActivity}: java.lang.ClassCastException: android.widget.Button cannot be cast to com.google.android.gms.common.SignInButton
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2339)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
at android.app.ActivityThread.access$600(ActivityThread.java:153)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1269)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5289)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:739)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ClassCastException: android.widget.Button cannot be cast to com.google.android.gms.common.SignInButton
at com.ferdiseegers.klantenbestand.Activities.LoginActivity.onCreate(LoginActivity.java:81)
at android.app.Activity.performCreate(Activity.java:5133)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2293)
... 11 more
我在示例项目的布局 XML 中使用了按钮
<com.google.android.gms.common.SignInButton
android:id="@+id/sign_in_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="30dip"/>
这就是我在活动中使用它的方式
public class LoginActivity extends Activity implements View.OnClickListener,
PlusClient.ConnectionCallbacks, PlusClient.OnConnectionFailedListener,
PlusClient.OnAccessRevokedListener {
private static final int DIALOG_GET_GOOGLE_PLAY_SERVICES = 1;
private static final int REQUEST_CODE_SIGN_IN = 1;
private static final int REQUEST_CODE_GET_GOOGLE_PLAY_SERVICES = 2;
private TextView mSignInStatus;
private PlusClient mPlusClient;
private SignInButton mSignInButton;
private View mSignOutButton;
private View mRevokeAccessButton;
private ConnectionResult mConnectionResult;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
mPlusClient = new PlusClient.Builder(this, this, this)
.setVisibleActivities("http://schemas.google.com/AddActivity", "http://schemas.google.com/BuyActivity")
.setScopes(Scopes.PLUS_LOGIN, Scopes.PLUS_PROFILE)
.build();
mSignInStatus = (TextView) findViewById(R.id.sign_in_status);
mSignInButton = (SignInButton) findViewById(R.id.sign_in_button);
mSignInButton.setOnClickListener(this);
mSignOutButton = findViewById(R.id.sign_out_button);
mSignOutButton.setOnClickListener(this);
mRevokeAccessButton = findViewById(R.id.revoke_access_button);
mRevokeAccessButton.setOnClickListener(this);
}
//some other methods not worth pasting here
}
它可能很简单,但我已经为此苦苦挣扎了 2 个小时。希望任何人都可以帮我一把!