Skip to content

Add view to JavaFx application #12

@Silfalion

Description

@Silfalion

Hi everyone,

I'm raising this issue because I was trying to add a view to a JavaFx application with the following lines:

FxViewer fxViewer = new FxViewer(ind.tony, FxViewer.ThreadingModel.GRAPH_IN_GUI_THREAD);
 fxViewer.addDefaultView(false);

but gives these error message:

Taches.xml
Exception in Application start method
java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:473)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:372)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:941)
Caused by: java.lang.RuntimeException: Exception in Application start method
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:973)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:198)
	at java.base/java.lang.Thread.run(Thread.java:844)
Caused by: java.lang.NoClassDefFoundError: org/graphstream/ui/view/GraphRenderer
	at main.start(main.java:42)
	at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:919)
	at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(PlatformImpl.java:449)
	at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(PlatformImpl.java:418)
	at java.base/java.security.AccessController.doPrivileged(Native Method)
	at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:417)
	at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
	at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
	at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:175)
	... 1 more
Caused by: java.lang.ClassNotFoundException: org.graphstream.ui.view.GraphRenderer
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
	... 10 more
Exception running application main

Here is my code:

import javafx.application.Application;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import org.graphstream.stream.file.FileSinkImages;
import org.graphstream.stream.file.FileSourceDGS;
import org.graphstream.ui.fx_viewer.FxViewer;
import org.graphstream.ui.view.Viewer;
import org.graphstream.ui.view.ViewerPipe;
import org.jdom2.JDOMException;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

public class main extends Application {


    public static void main(String[] args) throws IOException, InterruptedException {



        launch(args);

    }

    @Override
    public void start(Stage primaryStage) throws Exception {

        System.setProperty("org.graphstream.ui", "javafx");
        try {
            TaskManager.readXML();
        } catch (JDOMException e) {
            e.printStackTrace();
        }
        Individual ind = new Individual(10, 10);

        StackPane root = new StackPane();

        Viewer viewer = new Viewer(ind.tony, Viewer.ThreadingModel.GRAPH_IN_ANOTHER_THREAD);
        viewer.addDefaultView(false);
        FxViewer fxViewer = new FxViewer(ind.tony, FxViewer.ThreadingModel.GRAPH_IN_GUI_THREAD);
        fxViewer.addDefaultView(false);

        root.getChildren().add((Node) ind.tony);

        primaryStage.setScene(new Scene(root));
        primaryStage.show();
    }

    public void captureImage(Individual ind) throws IOException, InterruptedException {


        FileSinkImages pic = new FileSinkImages(FileSinkImages.OutputType.PNG, FileSinkImages.Resolutions.VGA);
        pic.setLayoutPolicy(FileSinkImages.LayoutPolicy.COMPUTED_FULLY_AT_NEW_IMAGE);
        pic.writeAll(ind.tony, "graph.png");

        ind.tony.display();


        FileSinkImages.OutputPolicy outputPolicy = FileSinkImages.OutputPolicy.BY_EVENT;
        String prefix = "prefix\\prefix_";
        FileSinkImages.OutputType type = FileSinkImages.OutputType.PNG;
        FileSinkImages.Resolution resolution = FileSinkImages.Resolutions.HD720;

        FileSinkImages fsi = new FileSinkImages( type, resolution );

        // Create the source

        FileSourceDGS dgs = new FileSourceDGS();

        // Optional configuration

        fsi.setStyleSheet(
                "graph { padding: 50px; fill-color: white; }" +
                        "node { fill-color: #3d5689; }" +
                        "edge { fill-color: black; }");

        fsi.setOutputPolicy( outputPolicy );
        fsi.setLayoutPolicy( FileSinkImages.LayoutPolicy.COMPUTED_FULLY_AT_NEW_IMAGE );
        fsi.setQuality(FileSinkImages.Quality.HIGH);

        // Images production

        dgs.addSink( fsi );

        fsi.begin(prefix);
        ind.tony.write("newDg.dgs");
        dgs.begin( "newDg.dgs" );
        while( dgs.nextStep() ){
            Thread.sleep(2000);
        }

        dgs.end();
        fsi.end();
       
    }
}

I'd like to know how to correct please, thanks for reading.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions