我正在尝试从 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);