Reputation: 3912
I have an app that I have published and integrated android leaderboard, but when I play the game with another user(user not added as tester in the playstore dashboard) the app is crashing when I try to submit the score. The app is already published and as I know it should work!?! Can someone tell me what can the problem be?
Here is my code:
private void submitScore(final int points) {
if (getApiClient().isConnected()) {
Log.d("--", "submiting score " + points);
PendingResult<Leaderboards.LoadPlayerScoreResult> result = Games.Leaderboards
.loadCurrentPlayerLeaderboardScore(getApiClient(),
getString(R.string.poeni_tabela),
LeaderboardVariant.TIME_SPAN_ALL_TIME,
LeaderboardVariant.COLLECTION_PUBLIC);
result.setResultCallback(new ResultCallback<Leaderboards.LoadPlayerScoreResult>() {
@Override
public void onResult(
Leaderboards.LoadPlayerScoreResult loadPlayerScoreResult) {
Games.Leaderboards.submitScore(getApiClient(),
getString(R.string.poeni_tabela),
loadPlayerScoreResult.getScore().getRawScore()
+ points);
}
});
}
}
And here is the log:
java.lang.NullPointerException
at com.myapp.QuizActivity$9.onResult(QuizActivity.java:611)
at com.myapp.QuizActivity$9.onResult(QuizActivity.java:1)
at com.google.android.gms.common.api.BaseImplementation$CallbackHandler.deliverResultCallback(Unknown Source)
at com.google.android.gms.common.api.BaseImplementation$CallbackHandler.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5196)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)
The line com.myapp.QuizActivity$9.onResult(QuizActivity.java:611)
is this code:
Games.Leaderboards.submitScore(getApiClient(),
getString(R.string.poeni_tabela),
loadPlayerScoreResult.getScore().getRawScore()
+ points);
Upvotes: 0
Views: 416
Reputation: 3912
OK, I've found the answer to my question thanks to @Jens. Seems like loadPlayerScoreResult.getScore().getRawScore()
is null
. This I suppose is because the player haven't submited any score yet so in that case you just add the initial score, and next time if its not null
- and it should not be, you can sum old points with the new ones.
here is the code that im using now in the submitScore
method above:
if (loadPlayerScoreResult.getScore() != null) {
Games.Leaderboards.submitScore(getApiClient(),
getString(R.string.poeni_tabela),
loadPlayerScoreResult.getScore().getRawScore()
+ points);
} else {
Games.Leaderboards.submitScore(getApiClient(),
getString(R.string.poeni_tabela), points);
}
Upvotes: 2
Reputation: 69440
There are more possibilities:
Games.Leaderboards is null
loadPlayerScoreResult is null
loadPlayerScoreResult.getScore() is null
loadPlayerScoreResult.getScore().getRawScore() is null
Use a debugger to find out what is happend.
Upvotes: 2