0
        import java.awt.Color;
        import java.awt.geom.Rectangle2D;
        import javax.swing.BorderFactory;
        import javax.swing.JFrame;
        import javax.swing.JScrollPane;
        import org.jgraph.JGraph;
        import org.jgraph.graph.DefaultEdge;
        import org.jgraph.graph.DefaultGraphCell;
        import org.jgraph.graph.DefaultGraphModel;
        import org.jgraph.graph.GraphConstants;
        import org.jgraph.graph.GraphModel;
        import com.mxgraph.swing.mxGraphComponent;
        import com.mxgraph.view.mxGraph;

        public class Graph extends JFrame
        {
                private static final long serialVersionUID = -2707712944901661771L;
                public Graph()
                {
                    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)
                {
                    Graph frame = new Graph();
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.setSize(400, 320);
                    frame.setVisible(true);
                }
        }

I added the executable jar file for JGraphx to my eclipse project and ran this code. But the error is as Exception in thread "main" java.lang.Error: Unresolved compilation problem:

at com.mxgraph.layout.orthogonal.model.Graph.main(Graph.java:47).

Is this an installation problem or problem with the code?

raj
  • 101
  • 1
  • 3
  • 11
  • Possible duplicate of [How to import a jar in Eclipse](https://stackoverflow.com/questions/3280353/how-to-import-a-jar-in-eclipse) – Marcos Vasconcelos Oct 20 '17 at 12:16
  • I followed the same procedure of importing a jar in Eclipse but still this error comes up. – raj Oct 20 '17 at 12:20
  • Add the full message/stacktrace of the error and point which line is the 47 – Marcos Vasconcelos Oct 20 '17 at 12:23
  • @MarcosVasconcelos I could succesfully run the program on Eclipse. But when I run it on CMD using javac -cp command the program succesfully compiles but on running it gives JNI error. Can someone help please? – raj Oct 20 '17 at 17:58
  • To run a jar with JNI you need to add the .dll/.so into classpath in the run command (dont remember how) – Marcos Vasconcelos Oct 20 '17 at 18:07

0 Answers0