Ich möchte grafisch mehrere Kreise ausgeben (am Ende soll das mal ein Binärbaum werden - aber alles Schritt für Schritt deshalb sind noch keine Linien vorhanden). Die Kreise sollen nicht irgendwo plaziert werden sondern es soll der Logik eines Binärbaums folgen. Dabei möchte ich erst einen Eingabeprozess der Werte starten und anschließend sollen die Kreise entsprechend der Werteingabe ausgegeben werden. Mein bisheriger Versuch erzeugt aber folgende Errormeldung:
Hier der bisherige Code:
Ich kann nicht nachvollziehen wo der Fehler ist obwohl ich nach der Fehlermeldung gegoogelt habe - Eclipse zeigt mir auch nicht an in welcher Zeile der Fehler ist. Ich habe schon ein ähnliches Programm geschrieben ohne grafische Ausgabe und dort läut alles wunderbar allerdings hätte ich das ganze natürlich schon grafisch (sieht einfach besser aus).
Danke
Exception in Application constructor
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Unable to construct Application instance: class Kreisversuch
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NoSuchMethodException: Kreisversuch.<init>()
at java.lang.Class.getConstructor0(Unknown Source)
at java.lang.Class.getConstructor(Unknown Source)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(Unknown Source)
... 1 more
Exception running application Kreisversuch
Hier der bisherige Code:
Code:
import javafx.scene.shape.*;
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.input.*;
import javafx.scene.Scene;
import javafx.scene.Group;
import javafx.scene.paint.Color;
import java.util.ArrayList;
import java.util.Scanner;
import javafx.scene.layout.Pane;
public class Kreisversuch extends Application
{
static Scanner userinput = new Scanner(System.in);
static int rootvalue;
static boolean addingnodes = true;
static String nodevalue;
static ArrayList<Integer> nodevaluelist = new ArrayList<Integer>();
static ArrayList<Circle> circles = new ArrayList<Circle>();
static Line line = new Line();
int root;
Kreisversuch left;
Kreisversuch right;
//this are our values to place the circles/nodes we start with root node
int x = 400;
int y = 10;
public Kreisversuch(int root)
{
this.root = root;
this.left = null;
this.right = null;
}
public void addNewNode(int value)
{
//when our value is smaler as the value from our parent we have to choose the left side
if(value <= root )
{
x = x - 25;
y = y + 25;
if(left == null)
{
left = new Kreisversuch(value);
Circle circle = new Circle(x, y, 10);
circles.add(circle);
}
//if there is already a placed node we jump in that node and do the procedure again by recursion
else
{
left.addNewNode(value);
}
}
//our value is higher compared to our parent node so we have to go to the right side
else
{
x = x + 25;
y = y + 25;
if(right == null)
{
right = new Kreisversuch(value);
Circle circle = new Circle(x, y, 10);
circles.add(circle);
}
//if there is already a placed node we jump in that node and do the procedure again by recursion
else
{
right.addNewNode(value);
}
}
}
public static void dialog()
{
System.out.println("Please insert value of root node");
try
{
rootvalue = Integer.parseInt(userinput.next());
}
catch (NumberFormatException e) {}
nodevaluelist.add(rootvalue);
while(addingnodes == true)
{
System.out.println("You can add another node value type 'no' when you are finished ");
nodevalue = userinput.next();
if(nodevalue.equals("no"))
{
addingnodes = false;
//is used for testing if input works fine
System.out.println("values of my nodelist");
for (Integer output : nodevaluelist)
{
System.out.println(output);
}
break;
}
else
{
try
{
nodevaluelist.add(Integer.parseInt(nodevalue));
}
catch (NumberFormatException e) {}
}
}
}
public static void main(String[] args)
{
launch(args);
}
public void start(Stage stage)
{
dialog();
Kreisversuch node = new Kreisversuch(nodevaluelist.get(0));
nodevaluelist.remove(0);
for(int input : nodevaluelist)
{
node.addNewNode(input);
}
//root circle
Circle circle = new Circle(400, 10, 10, Color.BLUEVIOLET);
circles.add(circle);
Pane root = new Pane();
Scene scene1 = new Scene(root, 800, 600);
root.getChildren().addAll(circles);
stage.setScene(scene1);
stage.show();
}
}
Ich kann nicht nachvollziehen wo der Fehler ist obwohl ich nach der Fehlermeldung gegoogelt habe - Eclipse zeigt mir auch nicht an in welcher Zeile der Fehler ist. Ich habe schon ein ähnliches Programm geschrieben ohne grafische Ausgabe und dort läut alles wunderbar allerdings hätte ich das ganze natürlich schon grafisch (sieht einfach besser aus).
Danke