not able to show data in Recycler View

37 Views Asked by At

I am getting some data from server in json format. I have a model class where I got all data from server and I put all data in a Array List. Now I am not able to get data in recyclerView.

MainActivity

public CopyOnWriteArrayList<PrisonerModel> inside1

 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        recyclerViewInside = findViewById(R.id.rv);

 signature_calculation_prisonerList();
        new PrisonerListAsyncTask().execute(NetworkUtils.PRISONER_LIST, ctimestamp,
                cnonce, cappkey, csign);
  inside1 = new CopyOnWriteArrayList<>();
        MyAdapter myAdapter = new MyAdapter(inside1, this, this);
        recyclerViewInside.setAdapter(myAdapter);
}

Model.java file

public class PrisonerModel {
    private String name;
    private  int image;
    private  int total_prisoner;
    private int outside;
    private int inside;
 
    private String imageUri;
    private String device;
    
    public PrisonerModel() {
    }

    public PrisonerModel(String name, int image) {
        this.name = name;
        this.image = image;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getImage() {
        return image;
    }

    public void setImage(int image) {
        this.image = image;
    }

    public int getTotal_prisoner() {
        return total_prisoner;
    }

    public int getOutside() {
        return outside;
    }

    public int getInside() {
        return inside;
    }

  

    public String getImageUri() {
        return imageUri;
    }

    public String getDevice() {
        return device;
    }

    public static PrisonerModel fromJson(JSONObject jsonObject)
    {
        PrisonerModel pm1 = new PrisonerModel();
        MainActivity ma = new MainActivity();
        try {
            pm1.total_prisoner = jsonObject.getInt("total");
            Log.e("total: ", String.valueOf(pm1.getTotal_prisoner()));
            JSONArray jsonArray = jsonObject.getJSONArray("list");
            ma.inside1 = pm1.fromJson(jsonArray);
            Log.e("inside: ", String.valueOf(ma.inside1.get(0).getName()));
            pm1.inside = pm1.x;
            pm1.outside = pm1.getTotal_prisoner() - pm1.x;

        } catch (JSONException e) {
            e.printStackTrace();
            return null;
        }
        return pm1;
    }

I am getting data of inside1 in this model class but when I use Log.e("") in Main Activity it throw error "ArrayOutOfBoundIndex"

could you help me where am i doing mistake?

0

There are 0 best solutions below