question

Abhimir avatar image
Abhimir asked

Game crash at LeaderboardsClient lbClient = agsClient.getLeaderboardsClient

When the device does not have a user logged in, then the game crashes with an Null pointer exception at this line LeaderboardsClient lbClient = agsClient.getLeaderboardsClient(); How should I handle this?
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Abhimir avatar image
Abhimir answered
That is apart from doing if (agsClient ! = null)
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Sujoy@Amazon avatar image
Sujoy@Amazon answered
Hi Abhimir, Please make sure that you receive a callback to onServiceReady() of AmazonGamesCallback after calling AmazonGamesClient.initialize() before making any further call to leader board apis. In your onCreate method, you should be doing the initialization work. You should call a method along these lines: private void initializeAmazonGameCircle() { agsCallback = new AmazonGamesCallback() { public void onServiceReady(AmazonGamesClient client) { agsClient = client; gameCircleAvailable = true; startingLevel = retrieveHighestLevelAttained(); gameController.getGameStateListener().onGameInitialized(); } public void onServiceNotReady(AmazonGamesStatus reason) { switch (reason) { // The SDK failed to initialize correctly. case CANNOT_INITIALIZE: break; // The SDK is in the process of initializing. case INITIALIZING: break; // The device not registered with an account case NOT_AUTHENTICATED: break; // The game is not authorized to use this service. case NOT_AUTHORIZED: break; } gameCircleAvailable = false; } }; } Message was edited by: Sujoy@Amazon
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.