我目前正在开发一个更大的项目,但能够将我的问题定位到一行:
java.awt.Desktop.getDesktop().browse(new URI("https://google.com"));
当尝试使用 Java 中的 java.awt.Desktop 类打开网站(例如 Google)时,以下 GTK 警告会两次打印到我的控制台。如何解决或抑制此警告?
[146880, Main Thread] WARNING: GTK+ module /snap/firefox/4090/gnome-platform/usr/lib/gtk-2.0/modules/libcanberra-gtk-module.so cannot be loaded.
GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported.: 'glib warning', file /build/firefox/parts/firefox/build/toolkit/xre/nsSigHandlers.cpp:187
(firefox:146880): Gtk-WARNING **: 21:05:50.793: GTK+ module /snap/firefox/4090/gnome-platform/usr/lib/gtk-2.0/modules/libcanberra-gtk-module.so cannot be loaded.
GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported.
Gtk-Message: 21:05:50.793: Failed to load module "canberra-gtk-module"
System.setErr(new PrintStream(new FileOutputStream("/dev/null")));
重定向标准错误流,但这并没有解决问题。Ubuntu 22.04.4 LTS 火狐浏览器 124.0.2(64 位)
任何想法表示赞赏。
就像 yvs2014 提到的那样,该消息仅在通过 snap 安装 Firefox 时出现,就像我的情况一样,也可能在通过 flatpak 安装时出现。要解决问题,只需按照 Mozilla 提供的官方下载即可。
注意:请记住在重新安装之前备份您的设置、密码、配置文件等。