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 ){
                      System.out.println(line);
                      //Reversing each line of string                        
                      StringBuilder sb =  new StringBuilder(line);
                      sb.reverse();
                      String RS = sb.toString();
                      System.out.println(RS);
                      //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
                                System.out.println(c);
                                si.next();
                            }
                            break;
                        }
                    }
                    JOptionPane.showMessageDialog(null, result);

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