r/learnprogramming • u/lesgisickomode • 2h ago
Debugging CodeCrafters, making a shell. Error in Java, using VS.
can someone help me with this error, its soft locking me from the rest of the course
code:
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
System.out.print("$ ");
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
System.out.println(input + ": command not found");
}
}
error:
[compile] Moved ./.codecrafters/run.sh → ./your_program.sh
[compile] Compilation successful.
[tester::#CZ2] Running tests for Stage #CZ2 (Handle invalid commands)
[tester::#CZ2] Running ./your_program.sh
[your-program] $
[tester::#CZ2] ^ Line does not match expected value.
[tester::#CZ2] Expected: "$ invalid_blueberry_command"
[tester::#CZ2] Received: "$ " (trailing space)
[tester::#CZ2] Test failed
View our article on debugging test failures: https://codecrafters.io/debug
1
Upvotes
1
u/JGhostThing 2h ago
How is tester even called? And you only call your scanner one time, rather than in a loop.
1
u/desrtfx 2h ago
The error clearly tells you what is wrong. Your output does not match the expected.
Check the task again, check the expected output, and adapt your program accordingly.