IllegalAccessError on FontAwesomeIcon construction

Issue #27 open
khaled bed created an issue

JDK 1.8.0_45 Attempting to construct an instance of FontAwesomeIcon results in IllegalAccessError:

Caused by: java.lang.IllegalAccessError: tried to access method com.sun.javafx.css.parser.CSSParser.<init>()V 

      from class de.jensd.fx.glyphs.GlyphIcon 

      at de.jensd.fx.glyphs.GlyphIcon.<clinit>(GlyphIcon.java:49)

Comments (6)

  1. Jens Deters repo owner

    Khaled,

    would you verify the java version again? Did you try with a newer JDK, e.g. 1.8.0_77?

    com.sun.javafx.css.parser.CSSParser is private API which has changed since 1.8.0_40.

    Jens

  2. khaled bed reporter

    yes I was using JDK 1.8.0_31 that's why it doesn't work for me.

    after updating to 1.8.0_92 version everything is working great..

    thank you so much guys for this awesome library

  3. jpsacha

    This is still an issue. com.sun.javafx.css.parser.CSSParser is not accessible in Java 9 resulting in java.lang.NoClassDefFoundError.

    In Java 9 there is now a public class 'javafx.css.CssParser' that could be used instead. Possible fix, assuming compilation with javac prior to 9, is to replace GlyphIcon#convert with dynamic invocation for Java 9:

    public Number convert(String sizeString) {
        if (System.getProperty("java.specification.version").substring(0, 1).compareTo("9") < 0) {
            com.sun.javafx.css.parser.CSSParser CSS_PARSER = new com.sun.javafx.css.parser.CSSParser();
            com.sun.javafx.css.ParsedValueImpl parsedValueImpl = CSS_PARSER.parseExpr("", sizeString);
            return (Number) parsedValueImpl.convert(getFont());
        } else {
            try {
                Class c = Class.forName("javafx.css.CssParser");
                Method parseExpr = c.getMethod("parseExpr", String.class, String.class);
                Object parser = c.newInstance();
                Object parsedValue = parseExpr.invoke(parser, "", sizeString);
                return (Number) ((ParsedValue) parsedValue).convert(getFont());
            } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | 
                        InstantiationException | InvocationTargetException e) {
                throw new RuntimeException("Failed to convert '" + sizeString + "' to a number. " + e.getMessage(), e);
            }
        }
    }
    
  4. Log in to comment