Android 从TurnBasedMatch获取参与者结果
所以我有一个TurnBasedMatch游戏。假设有两名球员,每人有一圈。现在轮到第二个玩家了。为了证明第二名玩家赢了,我做了以下操作:Android 从TurnBasedMatch获取参与者结果,android,multiplayer,google-play-games,Android,Multiplayer,Google Play Games,所以我有一个TurnBasedMatch游戏。假设有两名球员,每人有一圈。现在轮到第二个玩家了。为了证明第二名玩家赢了,我做了以下操作: mywinstatusresult = ParticipantResult.MATCH_RESULT_WIN; opponentwinstatusresult = ParticipantResult.MATCH_RESULT_LOSS; myplacing = 1; opponentplacing = 2; ParticipantResult myresul
mywinstatusresult = ParticipantResult.MATCH_RESULT_WIN;
opponentwinstatusresult = ParticipantResult.MATCH_RESULT_LOSS;
myplacing = 1;
opponentplacing = 2;
ParticipantResult myresult = new ParticipantResult(myParticipantId,mywinstatusresult,myplacing );
ParticipantResult opponentresult = new ParticipantResult(getNextParticipantId(),opponentwinstatusresult, opponentplacing);
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);
}
});
(第一个getResult()
获取ParticipantResult
对象,第二个获取结果int
值。)
我希望返回该玩家的结果,即值ParticipantResult.MATCH\u result\u LOSE
。但是,我得到了一个NullPointerExceptionmMatch
不为空,myParticipantId
也不为空
我做错了什么?我的解决方法是获取比赛数据并再次计算赢家,因为数据保存了分数,只是我希望通过获取先前通过的ParticipantResult
来获得更干净的方式
您知道如何实现这一点,或者是否确实可以实现这一点吗?语句的哪一部分返回空值?是getParticipant(myParticipantId)还是getResult()?我在我的应用程序中使用它,因此它确实可以实现。当您获得NullPointerException(由mMatch.getStatus()报告)时,匹配的状态是什么?
mMatch.getParticipant(myParticipantId).getResult().getResult()