我正在使用Lobo - Java Web Browser library,它给了我一个例外,经过一些研究,我确定这可能是由于该库已针对旧版本的 Java 编译。
代码如下:
import java.io.IOException;
import org.lobobrowser.html.UserAgentContext;
import org.lobobrowser.html.parser.DocumentBuilderImpl;
import org.lobobrowser.html.parser.InputSourceImpl;
import org.lobobrowser.html.test.SimpleUserAgentContext;
import org.xml.sax.SAXException;
public class Cobratest
{
public static void main(String[] args) throws SAXException, IOException
{
UserAgentContext uAgent = new SimpleUserAgentContext();
DocumentBuilderImpl docBuild = new DocumentBuilderImpl(uAgent);
docBuild.parse(new InputSourceImpl("http://dic.amdz.com/"));
}
}
堆栈跟踪是:
Exception in thread "main" java.lang.IncompatibleClassChangeError: Found interface sun.font.FontManager, but class was expected
at org.lobobrowser.util.gui.FontFactory.createFont(FontFactory.java:210)
at org.lobobrowser.util.gui.FontFactory.createFont_Impl(FontFactory.java:180)
at org.lobobrowser.util.gui.FontFactory.createFont(FontFactory.java:127)
at org.lobobrowser.util.gui.FontFactory.getFont(FontFactory.java:98)
at org.lobobrowser.html.style.StyleSheetRenderState.<clinit>(StyleSheetRenderState.java:43)
at org.lobobrowser.html.domimpl.NodeImpl.<clinit>(NodeImpl.java:39)
at org.lobobrowser.html.parser.DocumentBuilderImpl.createDocument(DocumentBuilderImpl.java:143)
at org.lobobrowser.html.parser.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:97)
当我检查时,org.lobobrowser.util.gui.FontFactory.createFont
我发现有一个名为的接口FontManager
与以前的 Java 版本不同。在这个FontFactory
类中,他们使用了一个不再可用的这个接口的类。我该如何解决这个问题?
界面FontManager
:
package sun.font;
import java.awt.Font;
import java.awt.FontFormatException;
import java.io.File;
public interface FontManager {
public static final int NO_FALLBACK = 0;
public static final int PHYSICAL_FALLBACK = 1;
public static final int LOGICAL_FALLBACK = 2;
public boolean registerFont(Font font);
public void deRegisterBadFont(Font2D font2d);
public Font2D findFont2D(String string, int i, int i1);
public Font2D createFont2D(File file, int i, boolean bln, CreatedFontTracker cft) throws FontFormatException;
public boolean usingPerAppContextComposites();
public Font2DHandle getNewComposite(String string, int i, Font2DHandle fdh);
public void preferLocaleFonts();
public void preferProportionalFonts();
}
以及库中使用的类不可用:
return FontManager.getCompositeFontUIResource(new Font(name, style, size));