Hallo Community,
ich möchte zwei Knoten Verbinden.Allerdings gibt er mir ein NULLPointerException aus.
Der Controller:
In der letzten Zeile setzt der Compiler den NullPointerException!
LinkedList.lastKnoten.kante.setPath(LinkedList.lastKnoten.getPredessor(),LinkedList.lastKnoten);
Hier die LinkedList:
Hier der Knoten:
Hier die Kante:
Hier die Klasse Kreis:
ich möchte zwei Knoten Verbinden.Allerdings gibt er mir ein NULLPointerException aus.
Der Controller:
Java:
public void handleMouseClicked(MouseEvent event)
{
for(Kreis kreis:kreise)
{
if(kreis.isClicked(event.getX(), event.getY()))
{
LinkedList.insert(kreis, null);
if(LinkedList.firstKnoten == LinkedList.currentKnoten)
{
LinkedList.firstKnoten.kreis.setFill(Color.RED);
}
if(LinkedList.lastKnoten != null)
{
LinkedList.lastKnoten.kreis.setFill(Color.BLUE);
LinkedList.lastKnoten.kante.setPath(LinkedList.lastKnoten.getPredessor(),LinkedList.lastKnoten);
In der letzten Zeile setzt der Compiler den NullPointerException!
LinkedList.lastKnoten.kante.setPath(LinkedList.lastKnoten.getPredessor(),LinkedList.lastKnoten);
Hier die LinkedList:
Java:
package application.model;
import java.util.Iterator;
public abstract class LinkedList implements Iterable<Object>, Iterator<Object> {
public static Knoten currentKnoten = null;
public static Knoten lastKnoten = null;
public static Knoten firstKnoten = null;
public static Knoten tempKnoten = null;
public static void insert(Kreis kreis, Kante kante)
{
if (currentKnoten == null)
{
currentKnoten = new Knoten(null,null, kreis, kante, null);
firstKnoten = currentKnoten;
tempKnoten = firstKnoten;
}
else
{
tempKnoten.setSuccessor(new Knoten(tempKnoten,null,kreis,kante,null));
lastKnoten = tempKnoten.getSuccessor();
tempKnoten = lastKnoten;
System.out.println("naechster");
}
}
Hier der Knoten:
Java:
package application.model;
import javafx.scene.shape.Line;
public class Knoten {
public static Knoten successor = null;
public Knoten predessor = null;
public Kreis kreis = null;
public Kante kante = null;
public Line line = null;
public Knoten(Knoten predessor,Knoten successor, Kreis kreis, Kante kante, Line line)
{
this.successor = successor;
this.predessor = predessor;
this.kreis = kreis;
this.kante = kante;
this.line = line;
}
// GETTER-SETTER-METHODS
public static Knoten getSuccessor() {
return successor;
}
public void setSuccessor(Knoten successor) {
this.successor = successor;
}
public Knoten getPredessor() {
return predessor;
}
public void setPredessor(Knoten predessor) {
this.predessor = predessor;
}
public Kreis getKreis() {
return kreis;
}
public void setKreis(Kreis kreis) {
this.kreis = kreis;
}
public static void add(Kreis kreis)
{
Knoten neuerKnoten = new Knoten( null, null, kreis, null, null);
}
}
Hier die Kante:
Java:
package application.model;
import javafx.event.EventHandler;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;
import javafx.scene.layout.AnchorPane;
public class Kante extends Line
{
public Knoten _kreis1;
public Knoten _kreis2;
public static Line path;
public AnchorPane paneCircles;
public Kante (Knoten kreis1 ,Knoten kreis2,AnchorPane paneCircles)
{
_kreis1=kreis1;
_kreis2=kreis2;
//this.path= new Line(kreis1.kreis.getCenterX(), kreis1.kreis.getCenterY(), kreis2.kreis.getCenterX(), kreis2.kreis.getCenterY());
this.path= new Line(LinkedList.currentKnoten.getPredessor().kreis.getCenterX(),LinkedList.currentKnoten.getPredessor().kreis.getCenterY(),LinkedList.currentKnoten.kreis.getCenterX(),LinkedList.currentKnoten.kreis.getCenterY());
this.paneCircles = paneCircles;
kreis1.kreis.setPath(path);
path.setStrokeWidth(5.);
path.setStroke(Color.BLACK);
public void setPath(Knoten predessor, Knoten currentKnoten)
{
Kante line_1 = new Kante(predessor,currentKnoten,paneCircles);
paneCircles.getChildren().add(line_1.path);
}
Hier die Klasse Kreis:
Java:
import javafx.event.EventHandler;
import javafx.scene.input.MouseEvent;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Line;
public class Kreis extends Circle
{
static final double RADIUS = 15;
int kreisnummer = 0;
protected Line path;
protected Color farbe;
protected int klickanzahl=0;
protected int kantenanzahl =0;
protected double xpos;
protected double ypos;
public Kreis ( double xpos, double ypos, int klickanzahl , int kantenanzahl, Color farbe, int Kreisanzahl){
// Von Superklasse Circle geerbt
this.setCenterX(xpos);
this.setCenterY(ypos);
//xpos
this.setRadius(RADIUS);
this.setFill(Color.GREEN);
this.farbe = farbe;
this.klickanzahl = klickanzahl;
this.kantenanzahl = kantenanzahl;
kreisnummer = Kreisanzahl;
setOnMouseClicked(new EventHandler<MouseEvent>()
{
@Override
public void handle(MouseEvent t)
{
//setFarbe(Color.RED);
System.out.println("fenerbahce");
}
});
}
public Color setFarbe(Color Farbe)
{
return farbe = Farbe;
}
public Color getFarbe()
{
return farbe;
}
public void setKreisnummer(int nr)
{
kreisnummer =nr;
}
public int getKreisnummer()
{
return kreisnummer;
}
public void erhoeheCN()
{
klickanzahl = klickanzahl + 1;
}
public void erhoeheKN(){
kantenanzahl = kantenanzahl + 1;
}
public void verringerKantenanzahl()
{
kantenanzahl = kantenanzahl -1;
}
public void verringerKantenanzahlUm2()
{
kantenanzahl = kantenanzahl -2;
}
public int getKlickanzahl()
{
return klickanzahl;
}
public int getKantenanzahl()
{
return kantenanzahl;
}
public void setKlickanzahl(int anzahl)
{
klickanzahl=anzahl;
}
public void setPath(Line Lpath)
{
path = Lpath;
}
public Line getPath()
{
return path;
}
public void clearKlickanzahl()
{
klickanzahl=0;
}
// Wurde der Kreis getroffen?
public boolean isClicked(double x, double y)
{
return Math.abs(x - this.getCenterX()) < RADIUS + 5. && Math.abs(y - this.getCenterY()) < RADIUS + 5;
}
}
Danke für euer Hilfe !!!!