-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.

2
  • Where is this MMRafterDivision defined? Commented May 14, 2018 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 Commented May 14, 2018 at 11:53

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.