Hi,
Today is my first day learning java :)
I'm having problems running a very simple example (not a great start).
It's just a simple example that asks a user for input and prints it back out but I'm getting a null pointer exception when I try to read a line from the console.
I don't understand because everything seems to be instantiated.
public static void main(String[] args) {
// TODO code application logic here
Console console = System.console();
String userinput;
userinput= console.readLine("Enter input: ");
/* Creates list for planets */
ArrayList outputlist= new ArrayList();
outputlist.add(userinput); // Adds users input to the list
outputlist.add("an entry"); // Adds a string to the list
System.out.println("\nTwo items: " + outputlist);
}
EDIT 1
As a number of people have pointed out the error is thrown when I try to read a line from the console because console is null (even though I'm instantiating it ?).
I feel a bit silly asking this but how can I make the console "not null". Which I thought I was doing by using Console console = System.console().
My expectation of workflow was to write a simple user input using netbeans. Hit the debug button. See a screen pop up. Input some text. See the output.
EDIT 2
O.K
After a little digging around it turns out that you cannot use system.console within netbeans. I don't understand why. I just user scanner instead.
Now I'm not sure what answer to accept o-0