I try to get number of post from arraylist in the class into mainactivity. But it is wrong . Here is my code.

public static  int countNotify;
    public static List<Notification> bindNotifyData(JsonElement list)
        List<Notification> results= new ArrayList<>();
        JsonObject dataJsonObj = list.getAsJsonObject();
        // get data api from Json array "updates"
        JsonArray notifyJsonArray = dataJsonObj.get("updates").getAsJsonArray();
        ArrayList<Notification> notifyList = new ArrayList<>();
        if(notifyJsonArray != null && notifyJsonArray.size() > 0) {
            for(int i = 0; i < notifyJsonArray.size(); i++) {
                JsonObject notifyJson = (JsonObject) notifyJsonArray.get(i);
                Notification notification = new Notification();
                // Convert timestamp to Datetime
                String timestamp= notifyJson.get("time").getAsString();
                // count numbers of the post in the list json array.
        return results;

And in the MainActivity.class

 final int count=BindFetchDataHelper.countNotify;

But the value of count always is 0

1 Answers

ImNeos On

Try to create a instance of your class

BindFetchDataHelper bindFetchDataHelper = new BindFetchDataHelper ()

and then call final int count=bindFetchDataHelper.countNotify;

I had the same issue, it should work now.


Try like this :

public class BindFetchDataHelper {

private static int sTest;

static {
public static  int countNotify=0;


public static int getcountNotify() {
    return countNotify;

public static void setcountNotify(int setcountNotify) {
    this.countNotify = countNotify;

//your others functions

And now to access variable or to set it :

BindFetchDataHelper bindFetchDataHelper = new BindFetchDataHelper ()

bindFetchDataHelper.setcountNotify(YOURVALUE); //set

int whatyourwant = bindFetchDataHelper.getcountNotify(); //get