gpt4 book ai didi

java - GamesClient 未连接。错误 : "Call connect() and wait for onConnected() to be called."

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:30:15 25 4
gpt4 key购买 nike

我正在尝试使用 GamesClient 来使用 Google Play 游戏服务的排行榜。现在我有了它,所以当单击 importbutton 时,GamesClient 用于提交一些分数。如下所示,我收到一条错误消息,提示 connect() 并等待 onConnectd() 被调用。

我做错了什么?我在一些教程中看到了一个叫做 PlusClient 的东西。我需要以某种方式吗?如果需要,我可以提供更多代码。

StackOverflow 上似乎有很多关于这个新的 Google Play 游戏服务的问题,但没有太多答案。看起来人们仍在学习——就像我自己一样。 :)

LogCat

06-12 00:40:40.173: E/AndroidRuntime(1685): java.lang.IllegalStateException: Not connected. Call connect() and wait for onConnected() to be called.
06-12 00:40:40.173: E/AndroidRuntime(1685): at com.google.android.gms.internal.p.n(Unknown Source)
06-12 00:40:40.173: E/AndroidRuntime(1685): at com.google.android.gms.internal.p.o(Unknown Source)
06-12 00:40:40.173: E/AndroidRuntime(1685): at com.google.android.gms.internal.bj.a(Unknown Source)
06-12 00:40:40.173: E/AndroidRuntime(1685): at com.google.android.gms.games.GamesClient.submitScore(Unknown Source)
06-12 00:40:40.173: E/AndroidRuntime(1685): at matt.lyons.bibletrivia.lite.MainMenu$8.onClick(MainMenu.java:173)
06-12 00:40:40.173: E/AndroidRuntime(1685): at android.view.View.performClick(View.java:4204)
06-12 00:40:40.173: E/AndroidRuntime(1685): at android.view.View$PerformClick.run(View.java:17355)
06-12 00:40:40.173: E/AndroidRuntime(1685): at android.os.Handler.handleCallback(Handler.java:725)
06-12 00:40:40.173: E/AndroidRuntime(1685): at android.os.Handler.dispatchMessage(Handler.java:92)
06-12 00:40:40.173: E/AndroidRuntime(1685): at android.os.Looper.loop(Looper.java:137)
06-12 00:40:40.173: E/AndroidRuntime(1685): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-12 00:40:40.173: E/AndroidRuntime(1685): at java.lang.reflect.Method.invokeNative(Native Method)
06-12 00:40:40.173: E/AndroidRuntime(1685): at java.lang.reflect.Method.invoke(Method.java:511)
06-12 00:40:40.173: E/AndroidRuntime(1685): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-12 00:40:40.173: E/AndroidRuntime(1685): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-12 00:40:40.173: E/AndroidRuntime(1685): at dalvik.system.NativeStart.main(Native Method)

主菜单.java

public class MainMenu extends BaseGameActivity {

DatabaseHelper dh;
GamesClient client;
Context c;

@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.mainmenu);

client = getGamesClient();
client.connect();

c = this;

dh = new DatabaseHelper(this);
dh.openDB();

importbutton = (Button)findViewById(R.id.importbutton);

importbutton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
importScores();
}
});
}

public void importScores() {

final Dialog dialog = new Dialog(c);
dialog.setContentView(R.layout.importlayout);
dialog.setTitle(R.string.importtitle);

TextView question = (TextView)dialog.findViewById(R.id.question);
Button save = (Button)dialog.findViewById(R.id.save);
Button scratch = (Button)dialog.findViewById(R.id.scratch);

question.setText(c.getResources().getString(R.string.importquestion));
save.setText(c.getResources().getString(R.string.savebtn));
scratch.setText(c.getResources().getString(R.string.scratchbtn));

save.setOnClickListener(new OnClickListener() {
public void onClick(View v) {

long highestJC = dh.getHighestJC();
client.submitScore(c.getResources().getString(R.string.leaderboardjc), highestJC);

long highestTenC = dh.getHighestTenC();
client.submitScore(c.getResources().getString(R.string.leaderboardtenc), highestTenC);

long highestExodus = dh.getHighestExodus();
client.submitScore(c.getResources().getString(R.string.leaderboardexodus), highestExodus);

long highestGenesis = dh.getHighestGenesis();
client.submitScore(c.getResources().getString(R.string.leaderboardgenesis), highestGenesis);

long highestHolydays = dh.getHighestHolydays();
client.submitScore(c.getResources().getString(R.string.leaderboardholydays), highestHolydays);

long highestFacts = dh.getHighestFacts();
client.submitScore(c.getResources().getString(R.string.leaderboardfacts), highestFacts);

long highestActs = dh.getHighestActs();
client.submitScore(c.getResources().getString(R.string.leaderboardacts), highestActs);

long highestRandom = dh.getHighestRandom();
client.submitScore(c.getResources().getString(R.string.leaderboardrandom), highestRandom);

long highestAll = dh.getHighestAll();
client.submitScore(c.getResources().getString(R.string.leaderboardallcats), highestAll);

dialog.dismiss();
}
});

scratch.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
dh.deleteAll();
for(int i = 0; i < 15; i++) {
dh.insert(0, 0, "-");
}
dialog.dismiss();
dh.closeDB();
}
});

dialog.show();
}
}

最佳答案

如果您正在使用 BaseGameActivity,请不要调用 GamesClient.connect()。使用 BaseGameActivity 的优势在于它可以为您处理所有连接样板。您所要做的就是覆盖 onSignInSucceeded 并从那里进行 API 调用。在获得 onSignInSucceeded 之前,不要进行任何游戏 API 调用。

此外,请记住,当您的 Activity 获得 onStop 时,游戏 API 将断开连接。之后,当它随后获得 onStart 时,您将再次等待 onSignInSucceeded,然后再进行任何 API 调用。

关于java - GamesClient 未连接。错误 : "Call connect() and wait for onConnected() to be called.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17056104/

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