From 1e1838245155a975b6a995eeeb7a5fc8528364fa Mon Sep 17 00:00:00 2001 From: "Nelson R. Perez" Date: Thu, 9 Nov 2017 17:49:18 -0500 Subject: [PATCH] Avoiding a NullPointerException and using a sequential requestId in order to use this class with the NodeConnection --- .../graphenej/api/GetAccountBalances.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/graphenej/src/main/java/cy/agorise/graphenej/api/GetAccountBalances.java b/graphenej/src/main/java/cy/agorise/graphenej/api/GetAccountBalances.java index e8afee3..e9fe872 100644 --- a/graphenej/src/main/java/cy/agorise/graphenej/api/GetAccountBalances.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/GetAccountBalances.java @@ -4,6 +4,13 @@ import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; import com.neovisionaries.ws.client.WebSocket; import com.neovisionaries.ws.client.WebSocketFrame; + +import java.io.Serializable; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + import cy.agorise.graphenej.Asset; import cy.agorise.graphenej.AssetAmount; import cy.agorise.graphenej.RPC; @@ -12,12 +19,6 @@ import cy.agorise.graphenej.interfaces.WitnessResponseListener; import cy.agorise.graphenej.models.ApiCall; import cy.agorise.graphenej.models.WitnessResponse; -import java.io.Serializable; -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - /** * Class that implements get_account_balances request handler. * @@ -29,7 +30,7 @@ import java.util.Map; * */ public class GetAccountBalances extends BaseGrapheneHandler { - + private UserAccount mUserAccount; private List mAssetList; private boolean mOneTime; @@ -71,12 +72,14 @@ public class GetAccountBalances extends BaseGrapheneHandler { public void onConnected(WebSocket websocket, Map> headers) throws Exception { ArrayList params = new ArrayList<>(); ArrayList assetList = new ArrayList<>(); - for(Asset asset : mAssetList){ - assetList.add(asset.getObjectId()); + if(mAssetList != null){ + for(Asset asset : mAssetList){ + assetList.add(asset.getObjectId()); + } } params.add(mUserAccount.getObjectId()); params.add(assetList); - ApiCall apiCall = new ApiCall(0, RPC.GET_ACCOUNT_BALANCES, params, RPC.VERSION, 0); + ApiCall apiCall = new ApiCall(0, RPC.GET_ACCOUNT_BALANCES, params, RPC.VERSION, requestId); websocket.sendText(apiCall.toJsonString()); }