java 错误 Line nn: ';' expected
来源:网络收集 点击: 时间:2024-09-01这是因为字符串换行了。
有时你需要写一个长字符串。常见的错误是在字符串中输入了换行符。编译器就会报错:
Line nn: ; expected
2/5当这种情况发生时, 解决方案是将字符串拆分为两个, 确保字符串中都没有新行, 并将它们与 + 连接起来。因此, 您可以替换:
原来:String s = A very long string which just happens to go over the end of a line and causes a problem with the compiler;
修改后
String s = A very long string which just happens to go over the end +of a line and causes a problem with the compiler
3/5编辑器会提示
String literal is not properly closed by a double-quote

当我们编译时,报错
Example.java:4: 错误: 未结束的字符串文字
String s = A very long string which just happens to go over
^
Example.java:5: 错误: 需要;

我们把多行拼接起来,再次编译,就没报错了。

版权声明:
1、本文系转载,版权归原作者所有,旨在传递信息,不代表看本站的观点和立场。
2、本站仅提供信息发布平台,不承担相关法律责任。
3、若侵犯您的版权或隐私,请联系本站管理员删除。
4、文章链接:http://www.1haoku.cn/art_1183268.html