I am trying to iterate through a string and save the characters in a character array. It iterates perfectly and prints the characters but when I try to save the characters in the Array or in a List, it gives me NullPointerException. Can anyone point out the mistake I am doing here?

try {

                    List<String> result = Files.readAllLines(Paths.get("C:\\Users\\Rehan\\Documents\\NetBeansProjects\\Marks\\build\\classes\\marks\\input.txt"));
                    List<Character> marksC = null;                     
                    for(String line : result ){
                      //Reversing each line of string                        
                      StringBuilder sb =  new StringBuilder(line);
                      String RS = sb.toString();
                      //To read first sequence of integers in reversed string                            
                      StringCharacterIterator si = new StringCharacterIterator(RS, 0);
                        for(int i = 0; i <= RS.length() ; i++){
                            while (si.current()!=' '){
                                char c = si.current();
                                marksC.add(c); //This line giving NullPointerException
                    JOptionPane.showMessageDialog(null, result);

This article has been dead for over six months. Start a new discussion instead.