我使用此代码从排行榜中获得最高分,但我一直在获得


  java.lang.IllegalStateException





  LeaderboardScore lbs = arg0.getScores()。get(0);


而且我不知道怎么了。它在我以前的项目中起作用

public void updateTops() {
            Games.Leaderboards.loadTopScores(client, getString(R.string.leaderboard_score),
                    LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC, 2, true).
                    setResultCallback(new ResultCallback<Leaderboards.LoadScoresResult>() {
                        @Override
                        public void onResult(final Leaderboards.LoadScoresResult arg0) {
                            System.out.println("SUKA " + score);
                            LeaderboardScore lbs = arg0.getScores().get(0);
                            score = lbs.getDisplayScore();
                            name = lbs.getScoreHolderDisplayName();
                            arg0.getScores().close();
                        }
                    });
        }

最佳答案

以这种方式尝试:

 Games.Leaderboards.loadTopScores(mGamesClint,LEADERBOARD_ID, LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC, 5).setResultCallback(new ResultCallback<Leaderboards.LoadScoresResult>() {

        public void onResult(LoadScoresResult arg0) {

            if(arg0 != null) {
                 if (arg0.getStatus().getStatusCode() == GamesStatusCodes.STATUS_OK) {

                   int size = arg0.getScores().getCount();
                   LeaderboardScoreBuffer scoreBuffer = arg0.getScores();
                   Iterator<LeaderboardScore> it = scoreBuffer.iterator();
                   while(it.hasNext()){
                        LeaderboardScore temp = it.next();
                        Log.d("PlayGames", "player"+temp.getScoreHolderDisplayName()+" score:"+temp.getDisplayScore());
                   }
                }
            }
  }

10-07 20:07