IntelliJ IDEA编码/编译异常及程序文件夹为空问题求助
IntelliJ IDEA运行Secret Message程序时的异常问题
问题详情
- 在IntelliJ IDEA中运行名为Secret Message的Java程序时始终触发异常,尝试复制完整文件路径无法解决问题
- 切换使用UTF-8或ISO-8859-1编码,都会触发相同类型的异常,仅异常中的编码标识不同
- 补充:Jetbrains程序文件夹为空
运行命令
"C:\Program Files\Java\jdk-21\bin\java.exe" "-javaagent:C:\Users\forel\AppData\Local\Programs\IntelliJ IDEA Community Edition\lib\idea_rt.jar=55495:C:\Users\forel\AppData\Local\Programs\IntelliJ IDEA Community Edition\bin" -Dfile.encoding=ISO-8859-1 -Dsun.stdout.encoding=ISO-8859-1 -Dsun.stderr.encoding=ISO-8859-1 -classpath "C:\Users\forel\IdeaProjects\Secret Message\out\production\Secret Message" SecretMessage
程序代码
import java.util.Scanner; public class SecretMessage { public static void main(String[] args) { Scanner scn = new Scanner(System.in); String str = scn.nextLine(); String newStr = encode(str); System.out.println(newStr); } public static String encode(String str) { String letters = "abcdefghijklmnopqrstuvwxyz"; String enc = "kngcadsxbvfhjtiumylzqropwe"; for (int i = 0; i < str.length() - 1; i++) { str = str.toLowerCase(); } for (int i = 0; i < str.length() - 1; i++) { for (int j = 0; j < str.length() - 1; j++) { if (letters.charAt(i) == enc.charAt(j)) { str = str.replace(str.charAt(i), enc.charAt(j)); } } } return str; } }
额外说明
- 代码本身没有语法报错,流程为:输入字符串→创建密码表→循环处理转换→输出到控制台
- 密码循环逻辑可自行排查,当前优先级为解决运行时异常问题
内容的提问来源于stack exchange,提问作者Samuel Forel
相关产品推荐
相关产品推荐

