Hello, I am working on the Log Levels exercise. My intention is to return the string message. I used the substring method to locate this.
public class LogLevels {
public static String message(String logLine) {
throw new UnsupportedOperationException("Please implement the (static) LogLevels.message() method");
return logLine.substring(11);
}
public static String logLevel(String logLine) {
throw new UnsupportedOperationException("Please implement the (static) LogLevels.logLevel() method");
}
public static String reformat(String logLine) {
throw new UnsupportedOperationException("Please implement the (static) LogLevels.reformat() method");
}
}
I am getting this error
./src/main/java/LogLevels.java:6: error: unreachable statement
return logLine.substring(11);
^
My goal was to find the start of the whitespace in the string, I used that as a marker to identify the beginning of the message. I then moved one index over to the first character of the message, which was at 11. With this idea, I was hoping to extract the message from the string, using the substring method. By not passing a second argument to substring, it should extra to the end of the string.
I did some research, one question I had was, how could I test this code without a main method for the entry point, I learned that some classes do not need main methods. I assumed we are using this code as a Utility class, to process long messages.
throw new UnsupportedOperationException("Please implement the (static) LogLevels.message() method");
I also tried my best research in order to learn this code, from what I learned, this code will throw this message if the method does not execute correctly?
I assumed the boilerplate code was the LogLevels.message() method, and it needed a simple way of extracting the message portion from the logLine string (being passed in as a parameter). I thought if I return that string (the parameter logLine), and call the substring method with it, at index 11 until the end of the string, that it should extract the message.
Am I processing this correctly? Or do I need to go in another direction entirely?
Thank you team! ![]()