我是新手所以请原谅我糟糕的编码习惯,但我遇到了IllegalStateException
错误,但我不知道为什么。
我正在制作一款游戏,我希望每场比赛的比赛为1回合。所以,如果你和我一起比赛并开始比赛,那么我将首先轮到你,然后向你发送所需的信息,然后你轮到你并将你的数据发回给比赛结果。
但是我在完成转弯时遇到了问题(“我的”是开始比赛的人)。我想将信息发送给其他玩家,但是(从我收集的内容)我将不得不完成比赛并发送所需的数据。我使用以下代码执行此操作:
String playerId = Games.Players.getCurrentPlayerId(mGoogleApiClient);
String myParticipantId = mMatch.getParticipantId(playerId);
ParticipantResult myresult = new ParticipantResult(myParticipantId,ParticipantResult.MATCH_RESULT_UNINITIALIZED, ParticipantResult.PLACING_UNINITIALIZED);
ParticipantResult opponentresult = new ParticipantResult(getNextParticipantId(),ParticipantResult.MATCH_RESULT_UNINITIALIZED, ParticipantResult.PLACING_UNINITIALIZED);
List<ParticipantResult> reportresult = new ArrayList<ParticipantResult>();
reportresult.add(myresult);
reportresult.add(opponentresult);
Games.TurnBasedMultiplayer.finishMatch(mGoogleApiClient, mMatch.getMatchId(),mTurnData.persist(), reportresult)
.setResultCallback(new ResultCallback<TurnBasedMultiplayer.UpdateMatchResult>() {
@Override
public void onResult(TurnBasedMultiplayer.UpdateMatchResult result) {
processResult(result);
}
});
我收到的错误在我的帖子底部提到。第2717行就是这一行:
ParticipantResult myresult = new ParticipantResult(myParticipantId,ParticipantResult.MATCH_RESULT_UNINITIALIZED, ParticipantResult.PLACING_UNINITIALIZED);
那我在这里做错了什么?据我所知,这应该工作......
老实说,我想避免发送参与者的结果,但由于我需要发送数据,我需要根据以下内容提及结果:com.google.android.gms.games.multiplayer.turnbased.TurnBasedMultiplayer.finishMatch(GoogleApiClient arg0, String arg1, byte[] arg2, List<ParticipantResult> arg3)
12-25 04:41:36.995: E/AndroidRuntime(19132): FATAL EXCEPTION: main
12-25 04:41:36.995: E/AndroidRuntime(19132): Process: com.devsid.quiz, PID: 19132
12-25 04:41:36.995: E/AndroidRuntime(19132): java.lang.IllegalStateException
12-25 04:41:36.995: E/AndroidRuntime(19132): at com.google.android.gms.internal.jx.K(Unknown Source)
12-25 04:41:36.995: E/AndroidRuntime(19132): at com.google.android.gms.games.multiplayer.ParticipantResult.<init>(Unknown Source)
12-25 04:41:36.995: E/AndroidRuntime(19132): at com.google.android.gms.games.multiplayer.ParticipantResult.<init>(Unknown Source)
12-25 04:41:36.995: E/AndroidRuntime(19132): at com.devsid.quiz.QuizActivity$52.onClick(QuizActivity.java:2717)
12-25 04:41:36.995: E/AndroidRuntime(19132): at android.view.View.performClick(View.java:4438)
12-25 04:41:36.995: E/AndroidRuntime(19132): at android.view.View$PerformClick.run(View.java:18439)
12-25 04:41:36.995: E/AndroidRuntime(19132): at android.os.Handler.handleCallback(Handler.java:733)
12-25 04:41:36.995: E/AndroidRuntime(19132): at android.os.Handler.dispatchMessage(Handler.java:95)
12-25 04:41:36.995: E/AndroidRuntime(19132): at android.os.Looper.loop(Looper.java:136)
12-25 04:41:36.995: E/AndroidRuntime(19132): at android.app.ActivityThread.main(ActivityThread.java:5158)
12-25 04:41:36.995: E/AndroidRuntime(19132): at java.lang.reflect.Method.invokeNative(Native Method)
12-25 04:41:36.995: E/AndroidRuntime(19132): at java.lang.reflect.Method.invoke(Method.java:515)
12-25 04:41:36.995: E/AndroidRuntime(19132): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:732)
12-25 04:41:36.995: E/AndroidRuntime(19132): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:566)
12-25 04:41:36.995: E/AndroidRuntime(19132): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
我发现您无法在静态中保存匹配数据并仍然使用Google函数调用它,也许它以这种方式编码以阻止过多的流量。
您可以将matchID存储到变量中并使用它来确保您正在更新正确的匹配,但是您无法调用google匹配方法,否则您将获得NULL结果。
根据我的经验,您唯一可以调用google匹配方法的方法是在processResult()函数中。像这样......
public void processResult(UpdateMatchResult result) {
TurnBasedMatch updateMatch = result.getMatch();
否则数据陈旧。