-1

Below is spinet that I am using to make some simple division but it is working for small set of values when I am fetching a large no of data from DB it throws

java.lang.NumberFormatException: : For input string: "null"

List<String> MMRafterDivision = new ArrayList<>();
List<String> ReplaceNull = new ArrayList<>();
List<String> MMRDivisionMultiplier = new ArrayList<>();

public void MMRandMultiplier() {

    MMRafterDivision.add(null);
    MMRafterDivision.add("700");
    MMRafterDivision.add("900");
    ReplaceNull.add("1");
    ReplaceNull.add(null);

    for (int i = 0; i < ReplaceNull.size(); i++) {
        String strMMR = MMRafterDivision.get(i);
        String strMultiplier = ReplaceNull.get(i);
        if (strMMR == null && strMultiplier == null) {
            MMRDivisionMultiplier.add("null");
        }
        else if(strMMR == null && strMultiplier != null){
            MMRDivisionMultiplier.add("null");
        }
        else if(strMMR != null && strMultiplier == null) {
            MMRDivisionMultiplier.add(strMMR);
        }
        else{
            String result = String.valueOf(Double.valueOf(strMMR) / Double.valueOf(strMultiplier));
            MMRDivisionMultiplier.add(String.valueOf(result));
        }
    }
    System.out.println("MMR&MUL:"+MMRDivisionMultiplier);
}

Please help to rectify my mistake.

Lavish Khetan
  • 59
  • 1
  • 10
  • Where is this MMRafterDivision defined? – Adya May 14 '18 at 10:30
  • @Adya I have corrected the things and it works fine for small set of values, can you take a look and tell me why it does not work when I am fetching large set of data from DB – Lavish Khetan May 14 '18 at 11:53

1 Answers1

2

You added a null to the List:

ReplaceNull.add(null);

Then retrieved it and parsed it by:

Integer.parseInt(strMultiplier)

Since null is not a parsable int, NumberFormatException was thrown.

xingbin
  • 27,410
  • 9
  • 53
  • 103
  • I have corrected the code, can you please take a look now, since i have to fetch the data from the DB in real time and there are null, so i just cannot ignore it,I have to do this with null – Lavish Khetan May 14 '18 at 11:55