You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.10 03:15:18