I am not sure why I am getting a NullPointerException
on the line containing the while
loop.
Originally when the String[] input
is created. It is filled with null
so maybe that is why I was getting the error. I tried to fix this by adding this bit of code to change that:
for (String k : input) {
k = "empty";
}
This is probably the wrong approach so I am still getting the error.
code:
String[] input = new String[3];
while(!input[0].equals("exit")) {
Scanner sc = new Scanner(System.in);
input = sc.nextLine().split(" ", 3);
switch(input[0]) {
// vi
case "vi":
System.out.println("hi");
break;
// ls
case "ls":
break;
// mkdir
case "mkdir":
break;
// pwd
case "pwd":
break;
}
}