简体   繁体   English

整合Scoreloop高分

[英]Intregrating Scoreloop high scores

These two methods are called with no errors: 正确调用这两个方法:

public void submitScore(long scoreValue) {
        final Score score = new Score((double) scoreValue, null);
        final ScoreController scoreController = new ScoreController(
            (RequestControllerObserver) new ScoreSubmitObserver());
        scoreController.submitScore(score);
    }

    private class ScoreSubmitObserver implements RequestControllerObserver {
        public void requestControllerDidFail
          (final RequestController requestController,
           final Exception exception) { }

        public void requestControllerDidReceiveResponse(
          final RequestController requestController) { }
    }

When I click a button and move to the `High Scores' activity, the following code is called: 当我单击一个按钮并转到“高分”活动时,将调用以下代码:

// this is on the onCreate() method
List<Score> list = getScores();  // Highscores line 214
if(list.size() == 0) {
    scoreList.get(0).setText(
      "LIST WILL BE MORE THAN 0 SO THIS TEXT WILL NOT BE SEEN");
}

//Retrieving scores from Scoreloop server.
public List<Score> getScores() {

    //Create an instance of the controller
     ScoresController myScoresController = new ScoresController(null);
             // highscores line 244

     //Set the searchlist. Default is globalScoreSearchList
     myScoresController.setSearchList(SearchList.getBuddiesScoreSearchList());

     //Set the mode for the controller.
     myScoresController.setMode(2);

     //Set the range length of scores to be retrieved. Default is 25
     myScoresController.setRangeLength(20);

     //Make the request to the server
     myScoresController.loadRangeForUser(Session.getCurrentSession().getUser());

     List<Score> retrievedScores = myScoresController.getScores();
     return retrievedScores;
}

This code crashes the app with the below LogCat output: 此代码使用下面的LogCat输出使应用程序崩溃:

 FATAL EXCEPTION: main
 java.lang.RuntimeException: Unable to start activity ComponentInfo{matt.lyons.bibletrivia.lite/matt.lyons.bibletrivia.lite.Highscores}: java.lang.IllegalArgumentException: observer parameter cannot be null
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
    at android.app.ActivityThread.access$600(ActivityThread.java:141)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:5039)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
    at dalvik.system.NativeStart.main(Native Method)
 Caused by: java.lang.IllegalArgumentException: observer parameter cannot be null
    at com.scoreloop.client.android.core.controller.RequestController.<init>(SourceFile:159)
    at com.scoreloop.client.android.core.controller.ScoresController.<init>(SourceFile:187)
    at com.scoreloop.client.android.core.controller.ScoresController.<init>(SourceFile:168)
    at matt.lyons.bibletrivia.lite.Highscores.getScores(Highscores.java:244)
    at matt.lyons.bibletrivia.lite.Highscores.onCreate(Highscores.java:214)
    at android.app.Activity.performCreate(Activity.java:5104)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
    ... 11 more

I commented in the line numbers in the code. 我在代码中注释了行号。 I am not sure what the IllegalArgumentException is in the LogCat. 我不确定LogCat中的IllegalArgumentException是什么。 My question is how to fix this error. 我的问题是如何解决此错误。

You create a new ScoresController with a null parameter (first line in getScores()). 使用空参数(getScores()的第一行)创建一个新的ScoresController。 What happens then, according to the stack trace you provided, is that this constructor calls another constructor in the same class, which tries to create a RequestController. 根据您提供的堆栈跟踪,然后发生的是,此构造函数调用了同一类中的另一个构造函数,该类试图创建RequestController。 I suspect that you are forwarding the null parameter to the RequestController constructor, which does not accept a null value for the observer parameter. 我怀疑您正在将null参数转发到RequestController构造函数,该构造函数不接受观察者参数的null值。

IllegalArgumentException usually denotes a bug, where a method receives a parameter it is not supposed to deal with. IllegalArgumentException通常表示一个错误,即方法接收到它不应该处理的参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM