This was part of the error: "
java.lang.NullPointerException
at com.codegym.task.task07.task0708.Solution.main(Solution.java:20)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)"
I have no clue what it means, and there's no simplification of the error at the top of the coding page. Can anyone explain why I'm getting this error? Thanks!
package com.codegym.task.task07.task0708;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/*
Longest string
*/
public class Solution {
private static List<String> strings;
public static void main(String[] args) throws Exception {
for (int i = 0; i <5; i++) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
strings.add(br.readLine());
}
int max = strings.get(0).length(); //initializes max for the future for-loops
for (int j = 0; j < strings.size(); j++) { //finds the largest # of letters
if (strings.get(j).length() >= max) {
max = strings.get(j).length();
}
}
for (int k = 0; k < strings.size(); k++) { //if same # of letters as max -> added to longest array
if (strings.get(k).length() == max) {
System.out.println(strings.get(k));
}
}
}
}