运行JGraphX Hello World示例的错误消息

时间:2012-07-30 20:54:14

标签: java ioexception jgraphx

当我在JGraphX包中运行HelloWorld.java示例时,我收到以下错误消息,并通过拖放来移动单元格。

  

java.io.IOException:数据转换失败:不是图像格式       at sun.awt.datatransfer.DataTransferer.translateTransferable(DataTransferer.java:1293)       at sun.lwawt.macosx.CDataTransferer.translateTransferable(CDataTransferer.java:131)       at sun.awt.datatransfer.DataTransferer $ 6.run(DataTransferer.java:2304)       at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)       at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:701)       at java.awt.EventQueue.access $ 000(EventQueue.java:102)       at java.awt.EventQueue $ 3.run(EventQueue.java:662)       at java.awt.EventQueue $ 3.run(EventQueue.java:660)       at java.security.AccessController.doPrivileged(Native Method)       at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain.java:76)       at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain.java:87)       at java.awt.EventQueue $ 4.run(EventQueue.java:676)       at java.awt.EventQueue $ 4.run(EventQueue.java:674)       at java.security.AccessController.doPrivileged(Native Method)       at java.security.ProtectionDomain $ 1.doIntersectionPrivilege(ProtectionDomain.java:76)       at java.awt.EventQueue.dispatchEvent(EventQueue.java:673)       at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)       at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)       at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)       at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)       at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)       at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)

我正在使用Eclipse Juno和Java SE 7 for Mac。 我不明白它,找不到任何解决方法。我真的陷入绝望。请帮帮我。

提前谢谢。

更新: HelloWorld.java代码

public class HelloWorld extends JFrame
{
    public HelloWorld()
    {
        super("Hello, World!");

        mxGraph graph = new mxGraph();
        Object parent = graph.getDefaultParent();

        graph.getModel().beginUpdate();
        try
        {
            Object v1 = graph.insertVertex(parent, null, "Hello", 20, 20, 80, 30);
            Object v2 = graph.insertVertex(parent, null, "World!", 240, 150, 80, 30);
            graph.insertEdge(parent, null, "Edge", v1, v2);
        }
        finally
        {
            graph.getModel().endUpdate();
        }

        mxGraphComponent graphComponent = new mxGraphComponent(graph);
        getContentPane().add(graphComponent);
    }

    public static void main(String[] args)
    {
        HelloWorld frame = new HelloWorld();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(400, 320);
        frame.setVisible(true);
    }
}

2 个答案:

答案 0 :(得分:2)

您可以通过将静态字段 enableImageSupport 设置为 false 来解决此问题。像这样:com.mxgraph.swing.util.mxGraphTransferable.enableImageSupport = false;

来源:http://jgraph.github.io/mxgraph/java/docs/com/mxgraph/swing/util/mxGraphTransferable.html#enableImageSupport

答案 1 :(得分:1)

这似乎是OS X和某些Java版本的特定内容,正在查看this bug report。此示例适用于OS X 10.8上当前Mac提供的JVM,即:

java version "1.6.0_33"
Java(TM) SE Runtime Environment (build 1.6.0_33-b03-424-11M3720)
Java HotSpot(TM) 64-Bit Server VM (build 20.8-b03-424, mixed mode)