gpt4 book ai didi

java - 集成 Scoreloop 高分

转载 作者:行者123 更新时间:2023-11-30 03:40:37 25 4
gpt4 key购买 nike

这两个方法调用没有错误:

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

当我点击一个按钮并移动到“高分” Activity 时,将调用以下代码:

// 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 是什么。我的问题是如何修复此错误。

最佳答案

您创建一个带有空参数的新 ScoresController(getScores() 中的第一行)。然后,根据您提供的堆栈跟踪,该构造函数会调用同一类中的另一个构造函数,该构造函数会尝试创建 RequestController。我怀疑您将 null 参数转发给 RequestController 构造函数,它不接受观察者参数的 null 值。

IllegalArgumentException通常表示一个错误,其中一个方法接收到一个它不应该处理的参数。

关于java - 集成 Scoreloop 高分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15801281/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com