首页 > 解决方案 > 运行 jar 文件时不支持的协议

问题描述

我最近制作了一款扫雷游戏,我正在尝试为其添加声音。目前我有以下代码:

try {
        AudioClip explosion = new AudioClip(Main.class.getResource("explosion.mp3").toString());
        explosion.play();
        }
        catch (Exception e) {
            Alert error = new Alert(AlertType.ERROR);
            error.setContentText(e.getLocalizedMessage() + e.toString());
            error.showAndWait();
        }

当我从 Eclipse 运行程序时,它按预期工作。但是,如果我将其导出到可运行的 .jar 中,则会出现异常。“不支持的协议“rsrc”java.land.UnsupportedOperationException:不支持的协议“rsrc”。

我尝试了一系列我在网上看到的包含音频文件的不同方法,但我只能让它在 Eclipse 中工作,而不是在 jar 中。

标签: javaresourcesprotocols

解决方案


推荐阅读