gpt4 book ai didi

android - ClassCastException android.widget.Button 到 com.google.android.gms.common.SignInButton

转载 作者:搜寻专家 更新时间:2023-11-01 08:02:53 24 4
gpt4 key购买 nike

我不知道我做错了什么,但我的 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"/>

这就是我在 Activity 中使用它的方式

    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 个小时。希望有人能帮帮我!

最佳答案

如果您在布局文件中将 Button 替换为 SignInButton,请尝试刷新并清除项目。还要检查布局文件中是否有另一个 Button @+id/sign_in_button

关于android - ClassCastException android.widget.Button 到 com.google.android.gms.common.SignInButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18578356/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com