【问题标题】:Parsing mathml document using JScience使用 JScience 解析 mathml 文档
【发布时间】:2010-07-06 06:34:27
【问题描述】:

我尝试使用 JScience 解析 mathml 文档但没有成功。以下是我的一段代码。

import JSci.io.*;
import JSci.mathml.*;
  .
  .
public class ParsingMathML(){
 try {
        ....
        //inputFile is an xml file containing mathml code
 InputSource file = new InputSource(new FileReader(inputFile));  
 MathMLParser parser = new MathMLParser();
 parser.parse(file);

 Object[] parseList = parser.translateToJSciObjects();
}catch (Exception e) {
 e.printStackTrace();
}
}

我从这里得到了错误,所以我不能做任何进一步的事情。以下是 StackTrace:

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: JSci/maths/fields/Ring$Member
 at JSci.io.MathMLParser.translateToJSciObjects(Unknown Source)
 at JSci.io.MathMLParser.translateToJSciObjects(Unknown Source)
 at mathML.ProcessMathML.processFile(ParsingMathML.java:109)
 at mathML.ProcessMathML.actionPerformed(ParsingMathML.java:72)
 at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
 at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
 at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
 at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
 at javax.swing.AbstractButton.doClick(Unknown Source)
 at javax.swing.plaf.basic.BasicMenuItemUI.doClick(Unknown Source)
 at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(Unknown Source)
 at java.awt.Component.processMouseEvent(Unknown Source)
 at javax.swing.JComponent.processMouseEvent(Unknown Source)
 at java.awt.Component.processEvent(Unknown Source)
 at java.awt.Container.processEvent(Unknown Source)
 at java.awt.Component.dispatchEventImpl(Unknown Source)
 at java.awt.Container.dispatchEventImpl(Unknown Source)
 at java.awt.Component.dispatchEvent(Unknown Source)
 at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
 at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
 at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
 at java.awt.Container.dispatchEventImpl(Unknown Source)
 at java.awt.Window.dispatchEventImpl(Unknown Source)
 at java.awt.Component.dispatchEvent(Unknown Source)
 at java.awt.EventQueue.dispatchEvent(Unknown Source)
 at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
 at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
 at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
 at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
 at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
 at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: JSci.maths.fields.Ring$Member
 at java.net.URLClassLoader$1.run(Unknown Source)
 at java.security.AccessController.doPrivileged(Native Method)
 at java.net.URLClassLoader.findClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(Unknown Source)
 at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
 at java.lang.ClassLoader.loadClass(Unknown Source)
 at java.lang.ClassLoader.loadClassInternal(Unknown Source)
 ... 31 more

另外,有人知道如何使用 MathMLApplyElementImpl、MathMLDocumentImpl 或 JSci.mathml 包中的任何其他类吗?

如果您能提供一些关于如何解析 mathml 文档的代码示例,那就太好了。

任何想法都将受到高度赞赏。 谢谢

【问题讨论】:

    标签: java parsing mathml jscience


    【解决方案1】:

    Cocnering 您的确切错误,似乎 JSci.maths.fields.Ring$Member 类不存在,这会在方法 JSci.io.MathMLParser.translateToJSciObjects 中引发 ClassNotFoundException。

    让我们去看看这个源代码。 在 MathMLParser 中,Ring.Member 最显着的用法是作为返回值。但它可以在许多地方找到。 而且,由于 Ring.Member 位于 JSci.maths.fields 中,它似乎与 MathMLParser 在同一个 JAR 中,我猜你的问题比简单的 ClassNotFoundException 复杂得多。

    首先,您能否打开 JScience jar 以确保 JSci.maths.fields.Ring$Member 确实存在?

    如果不是这样,您是否在同一个应用程序中使用多个类加载器? (像 OSGi 之类的东西)

    【讨论】:

    • 太棒了!谢谢瑞杜尔。我可以通过导入包 来修复该错误,如您所料,它包含 。但是,无论我在 parser.parse(file) 中使用哪个文件,parseList[] 都是一个空数组。你有什么主意吗?谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-10
    • 1970-01-01
    • 1970-01-01
    • 2015-03-23
    • 2012-11-02
    • 2012-01-08
    相关资源
    最近更新 更多