I am having an issue creating a custom console, on the following code:
public class UserConsole {
protected static BlockingQueue<String> inputData;
private final static JTextArea textArea = new JTextArea();
private static JTextField textField = new JTextField("");
private void createGUI() {
final KeyListener returnAction = new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyChar() == '\n') {
returnInput();
}
}};
}
private void returnInput() {
//Here is the problem, the BlockingQueue throws a NullPointerException, which is strange, because the...
//...right after "System.out.println(textField.getText());" works perfectly fine.
inputData.offer(textField.getText());
System.setOut(userStream);
System.out.println(textField.getText());
textField.setText("");
System.setOut(nebulaStream);
}
}
I tried searching online, but didn't find anything, also tried adding .toString()
but it does not work as well.
As far as I know, a BlockingQueue cannot be initialized... So my final question is. Why is the BlockingQueue not reading the JTextField's string, and how can it be solved?
I hope it is not something obvious that I missed, every help is appreciated!