java.lang.NullPointerException: Cannot invoke method equalsIgnoreCase() on null object

Hi, I am trying to read the csv file and fetch the headers and related values in the map and convert it to a list because I want two different lists of emails matching with specific column values as Y and N. If that column is Y, it should return some list of emails present in the CSV file, and if it is N, it should return another list of emails.

My code is below, and it works perfectly in IntelliJ, but I need to use Katalon, and it throws a null pointer exception.

	public void readCSVUsingMapAndList() {
		String header = "";
		String[] headerArray = null;
		String csvLine = "";
		String[] csvLineArray = null;
               File file = new File("C:\\Users\\ju9964\\CREME_MKTG_EMAIL_CONSENT_20220727_01.csv");

		Map<String,String> values = new HashMap();
		Map<String, List<String>> emailList = new HashMap<>();
		List<String> YList = new ArrayList<>();
		List<String> NList = new ArrayList<>();
		try {
			BufferedReader br = new BufferedReader(new FileReader(file))

			if((header = br.readLine()) != null) {
				if(header != null && header != "")
					headerArray = header.split(",");
			while ((csvLine = br.readLine()) != null)  //returns a boolean value
				csvLineArray = csvLine.split(",");
				for (int count = 0; count < headerArray.length; count++) {
					values.put(headerArray[count], csvLineArray[count]);

				}else {
		}catch(Exception e) {

Note: If I use equals() method instead of equalsIgnoreCase, it always returns null values.

Can someone please help me to solve this?

Try to scan the values hashmap and print out all the elements in it to see if you parse the file and insert the elements in the hashmap correctly. An alternative to BufferedReader() is using CSVReader() which handle more sophisticated CSVs better. You can read more about it here.

Where is file defined?

I have defined it as static and kept at outside of this method. Forgot to add it here. Now I have updated here in code block.

I am able to get the results for values object but not able to get any key from it. i.e.,values.get(‘PERM_OVERALL’) returns null but values object has key-value pair data. But the same code works perfectly in Intellij.

Maybe try values["PERM_OVERALL"] to get the value from the key.

Tried the same values[“PERM_OVERALL”], but still it returns null value.
When I print the values in the console, am getting below results. Still not able to get any key from the values object.


If I understand your code right, values object is a list of maps.
So you have to iterate over it and get the value of the key at a given index, sort of: