簡體   English   中英

整合Scoreloop高分

[英]Intregrating Scoreloop high scores

正確調用這兩個方法:

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) { }
    }

當我單擊一個按鈕並轉到“高分”活動時,將調用以下代碼:

// 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;
}

此代碼使用下面的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

我在代碼中注釋了行號。 我不確定LogCat中的IllegalArgumentException是什么。 我的問題是如何解決此錯誤。

使用空參數(getScores()的第一行)創建一個新的ScoresController。 根據您提供的堆棧跟蹤,然后發生的是,此構造函數調用了同一類中的另一個構造函數,該類試圖創建RequestController。 我懷疑您正在將null參數轉發到RequestController構造函數,該構造函數不接受觀察者參數的null值。

IllegalArgumentException通常表示一個錯誤,即方法接收到它不應該處理的參數。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM