我正在尝试调用 XSL 样式表中的方法,例如 getFullName()
。该方法属于 Person
类,它是 Student
的父类(super class)。我在 XSL 样式表命名空间中定义了 Student
类,如下所示:xmlns:std="java:example.code.Student"
。但是,在运行时,我收到以下两个错误:example.code.abstract.Person
的 ClassNotFoundException 和 NoClassDefFoundError。似乎 Person 的类定义在运行时不可用? Student
对象不应该有权访问其父对象的方法吗?
最佳答案
Seems like the class definitions for Person isn't available during runtime?
是的,这就是错误的正确解释。
Shouldn't the Student object have access to its parent's methods?
是的,Student 对象将可以访问父对象的非私有(private)方法。也就是说,前提是父类的类在运行时可用。换句话说,子类没有嵌入父类的方法,因此需要父类可供访问。
子类加载期间父类不可用,导致NoClassDefFoundError。您需要确保父类和子类在运行时都可用,以防止发生错误。
关于java - XSLT 未调用属于 Java 父类的方法 : ClassNotFoundException & NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6260255/