Why am I continuing to get a NullPointerException? I've tried s.equals(""), s == null, s.length() == 0, !s.equals(""), !s.equals(null) and no matter what, I've continued to receive the NPE error message. Why?
package com.codegym.task.task07.task0727;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
Changing functionality
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> list = new ArrayList<String>();
String s = "";
while (true) {
s = reader.readLine();
if(s.equals("")) {
break;
} else {
list.add(s);
}
}
ArrayList<String> oddList = new ArrayList<String>();
String word = "";
for(int i = 0; i < list.size(); i++) {
word = list.get(i);
if(word.equals("")) {
oddList.add(word);
}
int length = word.length();
if(length % 2 == 0) {
oddList.add(word + " " + word);
} else {
oddList.add(word + " " + word + " " + word);
}
}
for(String words : oddList) {
System.out.println(words);
}
// ArrayList<String> listUpperCase = new ArrayList<String>();
// for (int i = 0; i < list.size(); i++) {
// String s = list.get(i);
// listUpperCase.add(s.toUpperCase());
// }
// for (int i = 0; i < listUpperCase.size(); i++) {
// System.out.println(listUpperCase.get(i));
// }
}
}