0

Hi i am writing code for filtering specific data based on the input. if input not available in database it throwing nullpointer exception on the list since i am new in java i dont know how to solve this error

private String isCreditRatingValid(String isin) {

        System.out.println(isin);
        List<Credit_rating_details> result = Credit.stream()
                                            .filter(i-> i.getIssuer_id()
                          .contains(isin)).collect(Collectors.toList()); \\throwing NullPointerException on this line\\ 
        if(!result.isEmpty() ) {
            validCreditRating = result.get(0).getCredit_rating();
            return result.get(0).getCredit_rating();
        }else {
            return null;
        }  
3
  • Paste the stack-trace. Also check if Credit is null Commented Nov 3, 2018 at 7:32
  • @NicholasK i am declaring credit 'static ArrayList<Credit_rating_details> Credit = null;' Commented Nov 3, 2018 at 7:36
  • If this static list Credit is null, obviously null.stream() is throwing the exception. Why don't you initialize it? Commented Nov 3, 2018 at 7:38

1 Answer 1

1

As per your comment you are declaring it as

static ArrayList<Credit_rating_details> Credit = null;

which is causing the NPE as you are performing an operation on a null object. Change it to

static ArrayList<Credit_rating_details> Credit = new ArrayList<Credit_rating_details>();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.