调试时触发Detail formatter error错误,请求问题排查与解决
Hey there! Let's tackle both the debug formatter error you're encountering and the hidden bug in your string splitting code.
1. Fixing the "Detail formatter error: Evaluations must contain either an expression or a block of well-formed statements"
This error doesn't come from your actual code—it's a problem with your debugger's configuration or how you're using the debug evaluation tool:
- Check custom detail formatters: If you're using an IDE like Eclipse or IntelliJ, you might have a custom detail formatter set up for a class (like
String) that has invalid syntax. For example, in Eclipse, go toWindow > Preferences > Java > Debug > Detail Formattersand look for any formatter entries with malformed code (missing semicolons, invalid expressions, etc.). Delete or fix those entries. - Verify debug expressions: If you were trying to evaluate an expression in the debug console/watch window, make sure what you entered is a valid Java expression or statement block. For example, don't leave incomplete code snippets—ensure it's either a single expression (like
content.length()) or a properly formatted block (with curly braces and semicolons if needed).
2. Fixing the String Splitting Bug in Your Code
Looking at your code, there's a critical issue with the split call that will cause unexpected behavior (even if the debug error is fixed):
try { content = new String(Files.readAllBytes(Paths.get(inputFile))); } catch (IOException e) { e.printStackTrace(); } // This line is problematic! String[] parts = content.split(".");
The split method uses regular expressions, and . in regex matches any character. So calling split(".") will split the string at every single character, resulting in an empty array (or an array of empty strings) instead of splitting on actual dots.
To fix this, you need to escape the dot twice (once for Java string escaping, once for regex escaping):
String[] parts = content.split("\\.");
If you want to handle cases where there might be multiple dots or trailing/leading empty strings, you can also add regex flags or adjust the split pattern, but the double-escaped dot is the core fix here.
内容的提问来源于stack exchange,提问作者Rom

