当我在mac上运行时,jfxpanel就会崩溃。它在windows中运行良好,但在mac下出现错误来,看起来与字体有关,但不确定原因,请帮助。
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at com.sun.t2k.MacFontFinder.initPSFontNameToPathMap(MacFontFinder.java:339)
at com.sun.t2k.MacFontFinder.getAllAvailableFontFamilies(MacFontFinder.java:359)
at com.sun.t2k.T2KFontFactory.getFontFamilyNames(T2KFontFactory.java:1056)
at com.sun.prism.j2d.J2DFontFactory.getFontFamilyNames(J2DFontFactory.java:52)
at com.sun.webpane.sg.prism.WCFontImpl.getFont(WCFontImpl.java:37)
at com.sun.webpane.sg.prism.FXGraphicsManager.getWCFont(FXGraphicsManager.java:56)
at com.sun.webpane.webkit.network.URLLoader.twkDidFinishLoading(Native Method)
at com.sun.webpane.webkit.network.URLLoader.access$1300(URLLoader.java:44)
at com.sun.webpane.webkit.network.URLLoader$6.run(URLLoader.java:691)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
Invalid memory access of location 0x0 rip=0x11c8c7b64
Segmentation fault: 11发布于 2015-10-27 10:44:27
您使用的运行时环境与JavaFX不兼容。
那是不明智的。JavaFX与Apple Java Runtime for Mac兼容的版本从未发布过。如果您希望Mac的8+能够正常工作,则应该使用Oracle 8+或OpenJDK 8+。如果您不能使用这些兼容的运行时之一,则不建议使用JavaFX。
如果您使用application是因为担心您的应用程序在用户机器上可用的Java运行时,那么请考虑将您的应用程序打包为自给式应用,它将兼容的运行时嵌入到您的应用程序中,而不依赖于预先安装的运行时。
发布于 2015-11-24 11:18:48
你试过这种肮脏的黑客行为吗?我在某个地方读到,这个问题发生在OS /el Capitan上的JDK 7中,但是它很可能永远不会在JDK 7中得到解决。
所以我发现了这个肮脏的黑客,对我来说很管用.
if (isMac()) {
try {
final Class<?> macFontFinderClass = Class.forName("com.sun.t2k.MacFontFinder");
final Field psNameToPathMap = macFontFinderClass.getDeclaredField("psNameToPathMap");
psNameToPathMap.setAccessible(true);
if (psNameToPathMap.get(null) == null) {
psNameToPathMap.set(
null, new HashMap<String, String>());
}
final Field allAvailableFontFamilies = macFontFinderClass.getDeclaredField("allAvailableFontFamilies");
allAvailableFontFamilies.setAccessible(true);
if (allAvailableFontFamilies.get(null) == null) {
allAvailableFontFamilies.set(
null, new String[] {});
}
} catch (final Exception e) {
// ignore
}
}https://stackoverflow.com/questions/33353866
复制相似问题