I am creating a word-by-word palindrome ("yes I can, can I yes?") as follows: ''' public class Palindrome {
LinkedQueue<String> queue;
LinkStack<String> stack;
public Palindrome() {
LinkedQueue<String> queue = new LinkedQueue<>();
LinkStack<String> stack = new LinkStack<>();
}
public boolean isPalindrome(String sentence) {
String[] sentenceSplit = sentence.split(" ");
for(String word : sentenceSplit) {
queue.enqueue(word.toLowerCase());
stack.push(word.toLowerCase());
}
while (stack.top() == queue.front()){
stack.pop();
queue.dequeue();
}
if(stack.size() == 0) {
return true;
}
return false;
}
public static void main(String[] args) {
Palindrome test = new Palindrome();
test.isPalindrome("can you you can");
}
} ''' In here, it says I receive a nullpointerexception during my for each loop where I enqueue and push each string in the string array, I have tested the strings in the string array and they do exist, so why am I receiving this error? Thanks.