Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java GoogleSignInAccount不能为空_Java_Android - Fatal编程技术网

Java GoogleSignInAccount不能为空

Java GoogleSignInAccount不能为空,java,android,Java,Android,我正试图通过游戏服务在play store中将排行榜应用到我的游戏中 我很难实现这一点。我不是专家。我会补充说,游戏是用HTML,CSS,javascript制作的。我已经在控制台中生成了排行榜ID。我无法解决以下错误: 我忘了补充一点,游戏目前正在通过Android studio调试器通过连接到USB计算机的手机进行测试 错误: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pudz

我正试图通过游戏服务在play store中将排行榜应用到我的游戏中

我很难实现这一点。我不是专家。我会补充说,游戏是用HTML,CSS,javascript制作的。我已经在控制台中生成了排行榜ID。我无法解决以下错误:

我忘了补充一点,游戏目前正在通过Android studio调试器通过连接到USB计算机的手机进行测试

错误:

java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.pudzibreak/com.example.pudzibreak.MainActivity}:
java.lang.NullPointerException: GoogleSignInAccount must not be null
main活动

package com.example.pudzibreak;
导入android.content.Intent;
导入android.os.Bundle;
导入android.view.view;
导入android.webkit.WebView;
导入androidx.annotation.NonNull;
导入androidx.appcompat.app.AlertDialog;
导入androidx.appcompat.app.appcompat活动;
导入com.google.android.gms.auth.api.auth;
导入com.google.android.gms.auth.api.signin.GoogleSignIn;
导入com.google.android.gms.auth.api.signin.GoogleSignInAccount;
导入com.google.android.gms.auth.api.signin.GoogleSignInClient;
导入com.google.android.gms.auth.api.signin.GoogleSignInOptions;
导入com.google.android.gms.auth.api.signin.GoogleSignInResult;
导入com.google.android.gms.games.games;
导入com.google.android.gms.games.leadboardersclient;
导入com.google.android.gms.tasks.OnCompleteListener;
导入com.google.android.gms.tasks.OnSuccessListener;
导入com.google.android.gms.tasks.Task;
导入com.google.android.gms.common.SignInButton;
公共类MainActivity扩展AppCompatActivity实现View.OnClickListener{
私有静态最终字符串TAG=“XD”;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SignInButton SignInButton=findViewById(R.id.sign_in_按钮);
signInButton.setSize(signInButton.SIZE_标准);
findviewbyd(R.id.sign_in_按钮);
WebView WebView=(WebView)findViewById(R.id.WebView);
WebView.getSettings().setJavaScriptEnabled(true);
WebView.loadUrl(“file:///android_asset/myHtml.html");
显著地();
Games.getLeaderboardsClient(这个,GoogleSignIn.getLastSignedAccount(这个));
}
私人空间明显无效{
GoogleSignenOptions SignenOptions=GoogleSignenOptions.DEFAULT\u GAMES\u SIGN\u IN;
GoogleSignInAccount账户=GoogleSignIn.GetLastSignedAccount(此账户);
if(GoogleSignIn.hasPermissions(account,signInOptions.getScopeArray())){
GoogleSignInAccount SignedAccount=账户;
}否则{
GoogleSignInClient signInClient=GoogleSignIn.getClient(这是signInOptions);
重要客户
.silentSignIn()
.addOnCompleteListener(
这
新的OnCompleteListener(){
@凌驾
未完成的公共void(@NonNull任务){
if(task.issusccessful()){
GoogleSignInAccount SignedAccount=task.getResult();
}否则{
//做点什么
}
}
});
}
}
@凌驾
公共void onClick(视图){
if(view.getId()==R.id.sign\u in\u按钮){
StartSigningent();
}
}
私人静态最终国际RC_排行榜_UI=9004;
private void展示排行榜(){
Games.getLeaderboardsClient(此,Google登录。GetLastSignedAccount(此))
.getLeaderboardIntent(“XXXXXXXXXXXXX”)
.addOnSuccessListener(新的OnSuccessListener(){
@凌驾
成功时的公共无效(意图){
startActivityForResult(意向,RC_排行榜_UI);
}
});
}
专用静态最终int RC_SIGN_IN=900;
私有无效启动信号(){
GoogleSignInClient signInClient=GoogleSignIn.getClient(此,
谷歌登录。默认(游戏登录);
Intent=signInClient.getsigningent();
startActivityForResult(意向、RC登录);
}
@凌驾
受保护的void onActivityResult(int请求代码、int结果代码、意图数据){
super.onActivityResult(请求代码、结果代码、数据);
if(requestCode==RC\u登录){
GoogleSignInResult结果=Auth.GoogleSignInApi.getSignInResultFromIntent(数据);
if(result.issucess()){
//登录帐户存储在结果中。
GoogleSignInAccount signedAccount=result.getSignInAccount();
}否则{
字符串消息=result.getStatus().getStatusMessage();
if(message==null | | message.isEmpty()){
message=“XXX”;
}
新建AlertDialog.Builder(this).setMessage(message)
.setNeutralButton(android.R.string.ok,null).show();
}
}
展示排行榜();
}
};

Games.getLeaderboardsClient(这个,GoogleSignIn.getLastSignedAccount(这个));

在onCreate中调用并导致崩溃

GoogleSignIn.GetLastSignedAccount(此)
返回空值

如果没有“最后登录”,则必须返回null

你可以试试这个:

GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this)
if(account != null) {
    Log.d("TUT", "getting leaderboard client");
    Games.getLeaderboardsClient(this, account);
} else {
    Log.e("TUT", "no last sign in. Not getting leaderboard client.");
}

Games.getLeaderboardsClient(这个,GoogleSignIn.getLastSignedAccount(这个));

在onCreate中调用并导致崩溃

GoogleSignIn.GetLastSignedAccount(此)
返回空值

如果没有“最后登录”,则必须返回null

你可以试试这个:

GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this)
if(account != null) {
    Log.d("TUT", "getting leaderboard client");
    Games.getLeaderboardsClient(this, account);
} else {
    Log.e("TUT", "no last sign in. Not getting leaderboard client.");
}

设备上有谷歌帐号吗?如果没有