从Scoreloop服务器检索分数时没有返回任何列表

时间:2013-09-30 08:34:26

标签: android scoreloop

我正在尝试从Scoreloop服务器检索设备用户的分数。这是一个AndEngine游戏。我尝试了以下方法:

observer = new RequestControllerObserver() {
        @Override
        public void requestControllerDidFail(RequestController arg0,
                Exception arg1) {
            // TODO Auto-generated method stub

        }

        @Override
        public void requestControllerDidReceiveResponse(
                RequestController requestController) {
            // TODO Auto-generated method stub
            myScoresController = (ScoresController) requestController;
            myScoresController.setSearchList(SearchList
                    .getGlobalScoreSearchList());
            myScoresController.setMode(mode);
            myScoresController.setRangeLength(20);
            myScoresController.loadRangeForUser(Session.getCurrentSession()
                    .getUser());
            Log.i("score", "" + myScoresController.getScores().get(0).getResult());
            // List<Score> retrievedScores = myScoresController.getScores();
        }

Log.i()甚至没有显示出来。我也试过这个:

observer = new RequestControllerObserver() {

        @Override
        public void requestControllerDidFail(RequestController arg0,
                Exception arg1) {
            // TODO Auto-generated method stub

        }

        @Override
        public void requestControllerDidReceiveResponse(
                RequestController requestController) {
            // TODO Auto-generated method stub
        }
            myScoresController = new ScoresController(observer);
            myScoresController.setSearchList(SearchList
                    .getGlobalScoreSearchList());
            myScoresController.setMode(mode);
            myScoresController.setRangeLength(20);
            myScoresController.loadRangeForUser(Session.getCurrentSession()
                    .getUser());
            Log.i("score", "" + myScoresController.getScores().get(0).getResult());
            // List<Score> retrievedScores = myScoresController.getScores();

我正在尝试获取列表的第一个元素,然后是分数结果。但是没有列表出现。错误显示为:

java.lang.IndexOutOfBoundsException
java.util.Collections$EmptyList.get(Collections.java:102)

但我没有同时尝试上述两种方法。肯定有一个错误但是我没有看到它。

修改

我使用它的全班如下:

public class ScoreLoopUpdater implements Runnable {
private double score;
private int mode;
private RequestControllerObserver observer;
private ScoresController myScoresController = null;

public ScoreLoopUpdater(double _score, int _mode) {
    this.score = _score;
    this.mode = _mode;
}

public void run() {
    getGlobalHighscore();
    ScoreloopManagerSingleton.get().onGamePlayEnded(
            score, mode);
}

private void getGlobalHighscore() {
        //the above codes including observer go inside here.
    }

我正在使用这个场景打电话:

ScoreLoopUpdater scoreLoopUpdater = new ScoreLoopUpdater(theScore, theMode);
activity.runOnUiThread(scoreLoopUpdater);

1 个答案:

答案 0 :(得分:1)

在用一些例子做手势后,我终于想出了正确的方法:

private void getGlobalHighscore() {
    observer = new RequestControllerObserver() {

        @Override
        public void requestControllerDidFail(RequestController arg0,
                Exception arg1) {
            // TODO Auto-generated method stub

        }

        @Override
        public void requestControllerDidReceiveResponse(
                RequestController requestController) {
            // TODO Auto-generated method stub
            final ScoresController myScoresController = (ScoresController) requestController;
            Log.i("score", "" + myScoresController.getScores().get(0).getResult());
            // List<Score> retrievedScores = myScoresController.getScores();
        }

    };
    ScoresController myScoresController = new ScoresController(observer);
    myScoresController.setSearchList(SearchList
            .getGlobalScoreSearchList());
    myScoresController.setMode(mode);
    myScoresController.setRangeLength(20);
    myScoresController.loadRangeForUser(Session.getCurrentSession()
            .getUser());
}

只应在requestControllerDidReceiveResponse函数中调用getScores(),这意味着在收到回复后得到分数。