現在、私のアプリにGoogleのサインインを実装しようとしていますが、私がサインインしてGoogleの予定を開いたときに、私はGoogleアカウントを選択できましたが、今度はボタンを押すたびにクラッシュします... java.lang.RuntimeException | java.lang.NullPointerException Google Sign
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.name, PID: 14299
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=9001, result=-1, data=Intent { (has extras) }} to activity {com.name/com.name.LoginActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.toString()' on a null object reference
at android.app.ActivityThread.deliverResults(ActivityThread.java:4053)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4096)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1516)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
Causeed by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.toString()' on a null object reference
at com.name.LoginActivity.handleSignInResult(LoginActivity.java:125)
at com.name.LoginActivity.onActivityResult(LoginActivity.java:112)
at android.app.Activity.dispatchActivityResult(Activity.java:6915)
at android.app.ActivityThread.deliverResults(ActivityThread.java:4049)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4096)
at android.app.ActivityThread.-wrap20(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1516)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
私の方法
は以下のとおりです:public class LoginActivity extends AppCompatActivity implements View.OnClickListener, GoogleApiClient.OnConnectionFailedListener {
private static final String TAG = "SignInActivity";
private static final int RC_SIGN_IN = 9001;
private TextView mStatusTextView;
private ProgressDialog mProgressDialog;
private TextView Name;
private TextView Email;
private ImageView ProfilePic;
private RelativeLayout Account_layout;
private SignInButton signInButton;
private Button signOutButton;
private GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
//findViewById(R.id.sign_in_button).setOnClickListener((View.OnClickListener) this);
final PacketBuilder pb = new PacketBuilder();
final Context context = this;
signInButton = (SignInButton) findViewById(R.id.sign_in_button);
signInButton.setSize(SignInButton.SIZE_STANDARD);
signOutButton = (Button) findViewById(R.id.sign_out_button);
Name = (TextView) findViewById(R.id.account_name);
Email = (TextView) findViewById(R.id.account_email);
ProfilePic = (ImageView) findViewById(R.id.account_picture);
Account_layout = (RelativeLayout) findViewById(R.id.account_layout);
Account_layout.setVisibility(View.GONE);
signInButton.setOnClickListener(this);
signOutButton.setOnClickListener(this);
GoogleSignInOptions signInOptions = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().build();
mGoogleApiClient = new GoogleApiClient.Builder(this).enableAutoManage(this, this).addApi(Auth.GOOGLE_SIGN_IN_API, signInOptions).build();
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.sign_in_button:
signIn();
break;
case R.id.sign_out_button:
signOut();
break;
}
}
private void signIn()
{
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
startActivityForResult(signInIntent, RC_SIGN_IN);
}
private void signOut()
{
Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
updateUI(false);
}
});
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
handleSignInResult(result);
}
}
private void handleSignInResult(GoogleSignInResult result) {
Log.d(TAG, "handleSignInResult:" + result.isSuccess());
if (result.isSuccess()) {
// Signed in successfully, show authenticated UI.
GoogleSignInAccount acc = result.getSignInAccount();
String name = acc.getDisplayName();
String email = acc.getEmail();
String picture_url = acc.getPhotoUrl().toString();
Name.setText(name);
Email.setText(email);
Glide.with(this).load(picture_url).into(ProfilePic);
updateUI(true);
//mStatusTextView.setText(getString(R.string.signed_in_fmt, acc.getDisplayName()));
}
else
{
// Signed out, show unauthenticated UI.
updateUI(false);
}
}
private void updateUI(boolean signedIn) {
if (signedIn) {
findViewById(R.id.sign_in_button).setVisibility(View.GONE);
findViewById(R.id.account_layout).setVisibility(View.VISIBLE);
} else {
//mStatusTextView.setText(R.string.signed_out);
findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
findViewById(R.id.account_layout).setVisibility(View.GONE);
}
}
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
}
私はできない私は、次のエラーは、「サインイン」を押しているとき..私は私がインターネット上で見つけたソリューションを試みたが、彼らは私を助けていませんでし問題を見つける:(誰かが私を助けることを望む。
あなたのソリューションは私を助けました、ありがとうございます:) –
私はすでにそれをupvoted –