0

I am using map collection in Java. My code is below;

public void example(String var){
Map<String, String> params = new LinkedHashMap<String, String>();

params.put("data", var);

String jsonResult = Jsoup.connect(url).ignoreContentType(true).data(params).execute().body();
}

When var is null, I take an error which is java.lang.IllegalArgumentException: Data value must not be null.

2
  • 4
    as far as i know, its valid to put null referenced objects to a Map.. the IllegalArgumentException is not coming from the put statement, can you please post your stack trace. Also split up your long chained function to multiple lines (issue must be in that line), so you can clearly see where the issue is.. Commented Oct 4, 2015 at 16:04
  • As the exception says: Data value must not be null Commented Oct 4, 2015 at 16:30

1 Answer 1

3

The error seems to be in Jsoup#data that doesn't accept null value for any param. If you know var is null, then don't add the key/value pair in the map.

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.