线程“ main”中的异常java.lang.ClassCastException:类sun.font.CompositeFont无法转换为类sun.font.PhysicalFont(sun.font.CompositeFont和sun.font.PhysicalFont位于模块的java.desktop中。在solaris sparc 64位上使用JAVA 11加载程序(bootstrap)。 JDK版本:-11.0.2
在Solaris Sparc 64位上使用JDK 11.0.2运行我们的应用程序时,我们遇到此异常:-
Exception in thread "main" java.lang.ClassCastException: class sun.font.CompositeFont cannot be cast to class sun.font.PhysicalFont (sun.font.CompositeFont and sun.font.PhysicalFont are in module java.desktop of loader 'bootstrap')
at java.desktop/sun.font.SunFontManager.getDefaultPhysicalFont(SunFontManager.java:1086)
at java.desktop/sun.font.SunFontManager.initialiseDeferredFont(SunFontManager.java:965)
at java.desktop/sun.font.CompositeFont.doDeferredInitialisation(CompositeFont.java:287)
at java.desktop/sun.font.CompositeFont.getSlotFont(CompositeFont.java:376)
at java.desktop/sun.font.CompositeStrike.getStrikeForSlot(CompositeStrike.java:80)
at java.desktop/sun.font.CompositeStrike.getFontMetrics(CompositeStrike.java:95)
at java.desktop/sun.font.FontDesignMetrics.initMatrixAndMetrics(FontDesignMetrics.java:360)
at java.desktop/sun.font.FontDesignMetrics.<init>(FontDesignMetrics.java:351)
at java.desktop/sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:303)
at java.desktop/sun.swing.SwingUtilities2.getFontMetrics(SwingUtilities2.java:1231)
at java.desktop/javax.swing.JComponent.getFontMetrics(JComponent.java:1646)
at java.desktop/javax.swing.plaf.basic.BasicGraphicsUtils.getPreferredButtonSize(BasicGraphicsUtils.java:351)
at java.desktop/javax.swing.plaf.basic.BasicButtonUI.getPreferredSize(BasicButtonUI.java:474)
at java.desktop/javax.swing.JComponent.getPreferredSize(JComponent.java:1680)
int w = Math.max(74,toStartButton.getPreferredSize()。width + 2);
根据此JDK错误ID链接:-https://bugs.java.com/bugdatabase/view_bug.do?bug_id=8132850在JDK 8和JDK 9中得到了解决,但在JDK 11上仍然遇到此问题。我仔细检查了CompositeFont.java类。如解决方案中所述,条件被包围在try-catch块中,但仍然无法正常工作。
请帮助。