2

I'm following this official tutorial of graphStream. And I'm trying to run this example code taken from there:

import org.graphstream.graph.*;
import org.graphstream.graph.implementations.*;
    
public class Tutorial1 {
    public static void main(String args[]) {
        Graph graph = new SingleGraph("Tutorial 1");
    
        graph.addNode("A");
        graph.addNode("B");
        graph.addNode("C");
        graph.addEdge("AB", "A", "B");
        graph.addEdge("BC", "B", "C");
        graph.addEdge("CA", "C", "A");
    
        graph.display();
    }
}

And I'm getting the following error:

Exception in thread "main" java.lang.RuntimeException: Cannot launch viewer.
    at org.graphstream.graph.implementations.AbstractGraph.display(AbstractGraph.java:212)
    at org.graphstream.graph.implementations.AbstractGraph.display(AbstractGraph.java:204)
    at org.test.Test.main(Test.java:23)
Caused by: org.graphstream.util.MissingDisplayException: No valid display found. Please check your System.setProperty("org.graphstream.ui") statement.
    at org.graphstream.util.Display.getDefault(Display.java:79)
    at org.graphstream.graph.implementations.AbstractGraph.display(AbstractGraph.java:209)
    ... 2 more

I did exactly what the tutorial showed.
what am I missing? what does "No valid display found." means

Kfir Ettinger
  • 584
  • 4
  • 13

1 Answers1

2

If you are doing this in a Java application, you need to use version 1.3.

Add the following dependencies. Version 1.3

  • gs-core
  • gs-algo
  • gs-ui

Main

import org.graphstream.graph.*;
import org.graphstream.graph.implementations.*;
    
public class Main {
    public static void main(String args[]) {
        Graph graph = new SingleGraph("Tutorial 1");
        graph.setStrict(false);
        graph.setAutoCreate( true );
        graph.addNode("A");
        graph.addNode("B");
        graph.addNode("C");
        graph.addEdge("AB", "A", "B");
        graph.addEdge("BC", "B", "C");
        graph.addEdge("CA", "C", "A");
    
        graph.display();
    }
}

POM

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>sed.home</groupId>
    <artifactId>JavaTestArea</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <dependencies>
        <dependency>
            <groupId>org.graphstream</groupId>
            <artifactId>gs-core</artifactId>
            <version>1.3</version>
        </dependency>        
        <dependency>
            <groupId>org.graphstream</groupId>
            <artifactId>gs-algo</artifactId>
            <version>1.3</version>
        </dependency>
        <dependency>
            <groupId>org.graphstream</groupId>
            <artifactId>gs-ui</artifactId>
            <version>1.3</version>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>15</maven.compiler.source>
        <maven.compiler.target>15</maven.compiler.target>
    </properties>
</project>

Output enter image description here

If you use version 2.0, it needs to be done in a JavaFX, Swing, or Android application.

SedJ601
  • 12,173
  • 3
  • 41
  • 59
  • and I've tried to use version 1.3 and still no luck. the only difference is the error message, now it's - **No UI package detected!** instead of the message from the post - **No valid display found.** – Kfir Ettinger May 04 '22 at 08:54
  • I'm new to java's gui. do you know any code example for using Graphstream with swing or JavaFX I can use as a reference? – Kfir Ettinger May 04 '22 at 10:37
  • I got the same error you originally got until I used version 1.3. What version of Java are you using? What operating System? – SedJ601 May 04 '22 at 12:50
  • I have never tried this with `JavaFX`. I will give it a try today. – SedJ601 May 04 '22 at 12:58
  • 1
    "From the 2.0 version of GraphStream, the default viewer is no part of the gs-core package anymore. Viewers are available separately. Viewers are located in gs-ui-TECH modules, where TECH is the name of the GUI tech used" – lilalinux Feb 08 '23 at 18:31
  • 1
    I was able to get 2.0 to work by adding `gs-ui-swing` 2.0 as a dependency. – rveach Jun 15 '23 at 02:18