java - 运行 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 中。
解决方案
推荐阅读
- html - 我如何在 3 个 div 周围添加一条弯曲的虚线,如下图所示
- javascript - 身体上的 JavaScript 点击工作 1 次
- c# - 如何将列表转换为 SQLBulkCopy 的数据表
- firebase - 使用 APNS 令牌而不是 FCM 令牌的 Firebase 云函数消息传递
- vba - 打印文件 - 宏
- android - kotlin-stdlib-jre7 已弃用。请改用 kotlin-stdlib-jdk7
- swift - 无法在 Xcode 9 中存档
- node.js - Editing the context variables in Watson Assistant for a specific dialogue node using Node js
- asp.net - Web 服务返回 XML 标记而不是值
- react-native - 在 react native 中使用 props 传递变量和函数