mardi 20 octobre 2015

how to set null value to blank data in datamodel how to remove array index of Bound exception

  String productname[] = dbHelper.getProductName("Basmati Rice");
        dbHelper.open();
        String productQuantity[] = dbHelper.getProductQuantity("Basmati Rice");
        dbHelper.open();
        String productCost[] = dbHelper.getProductCost("Basmati Rice");
        dbHelper.open();
        String   productcount[] = dbHelper.getpurchesitemCount();
        List<DataModel> lstDataModel = new ArrayList<DataModel>();
        for (int i = 0; i < productname.length; i++) {
            DataModel datamodel = new DataModel();
            datamodel.setProdcutid(productId[i]);
            datamodel.setProductname(productname[i]);
            datamodel.setProdcutQuantity(productQuantity[i]);
            datamodel.setProdcutCost(productCost[i]);
            datamodel.setEachproductcount(productcount[i]);

            lstDataModel.add(datamodel);
        }

This is my code i am getting array index out of bound exception because i i have only 3size of productcount and other have 4 count of string array but loop is running 4 time coz i am taking 4 lenght loop i want to set value blank in datamodel if value will null please tell me how to fix it in java

Aucun commentaire:

Enregistrer un commentaire