gpt4 book ai didi

google 注册中的 java.lang.NullPointerException 抛出 null

转载 作者:太空宇宙 更新时间:2023-11-04 11:45:55 24 4
gpt4 key购买 nike

public class MainActivity extends AppCompatActivity  implements GoogleApiClient.OnConnectionFailedListener, View.OnClickListener {

public SignInButton login;
private TextView name;
private GoogleApiClient googleApiClient;
private GoogleSignInOptions signInOptions;
private static final int REQUEST_CODE = 100;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().build();

googleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this, this).addApi(Auth.GOOGLE_SIGN_IN_API, signInOptions).addApi(AppIndex.API).build();
login = (SignInButton) findViewById(R.id.login);
name = (TextView) findViewById(R.id.name);
login.setSize(SignInButton.SIZE_WIDE);
login.setScopes(signInOptions.getScopeArray());
login.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(googleApiClient);
startActivityForResult(signInIntent, REQUEST_CODE);
}
});
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == REQUEST_CODE) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
GoogleSignInAccount account = result.getSignInAccount();

name.setText(account.getDisplayName());
}

}

@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {

}

/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
public Action getIndexApiAction() {
Thing object = new Thing.Builder()
.setName("Main Page") // TODO: Define a title for the content shown.
// TODO: Make sure this auto-generated URL is correct.
.setUrl(Uri.parse("http://[ENTER-YOUR-URL-HERE]"))
.build();
return new Action.Builder(Action.TYPE_VIEW)
.setObject(object)
.setActionStatus(Action.STATUS_TYPE_COMPLETED)
.build();
}

@Override
public void onStart() {
super.onStart();

// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
googleApiClient.connect();
AppIndex.AppIndexApi.start(googleApiClient, getIndexApiAction());
}

@Override
public void onStop() {
super.onStop();

// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
AppIndex.AppIndexApi.end(googleApiClient, getIndexApiAction());
googleApiClient.disconnect();
}

}

enter image description here

 Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.common.SignInButton.setSize(int)' on a null object reference
at snapdirectcom.snap.MainActivity.onCreate(MainActivity.java:42)

厌倦了检查许多更改,但它们都不起作用

最佳答案

我注意到您打开了两个布局 - 仔细检查您评论中的 SignInButton 是否位于 Activity_login 中,因为这是正在搜索的布局,其他所有内容似乎都按顺序排列

关于google 注册中的 java.lang.NullPointerException 抛出 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42358568/

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