Problem mit JavaFX

burakcuece

Mitglied
Hallo,
mir wird dieser Fehler angezeigt. Was habe ich falsch gemacht ?

Java:
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.Error: Unresolved compilation problems:
Bound mismatch: The type MouseEvent is not a valid substitute for the bounded parameter <T extends Event> of the type EventHandler<T>
Bound mismatch: The type MouseEvent is not a valid substitute for the bounded parameter <T extends Event> of the type EventHandler<T>
Bound mismatch: The type MouseEvent is not a valid substitute for the bounded parameter <T extends Event> of the type EventHandler<T>
Bound mismatch: The type MouseEvent is not a valid substitute for the bounded parameter <T extends Event> of the type EventHandler<T>
MouseEvent cannot be resolved to a variable
MOUSE_CLICKED cannot be resolved to a variable
MouseEvent cannot be resolved to a variable
MOUSE_CLICKED cannot be resolved to a variable

at Main.start(Main.java:30)
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)
Exception running application Main
 
Zuletzt bearbeitet von einem Moderator:
Mit Syntax-Highlighting: [code=java]//JAVA CODE HERE [/code]
Java:
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.Error: Unresolved compilation problems:
Bound mismatch: The type MouseEvent is not a valid substitute for the bounded parameter <T extends Event> of the type EventHandler<T>
Bound mismatch: The type MouseEvent is not a valid substitute for the bounded parameter <T extends Event> of the type EventHandler<T>
Bound mismatch: The type MouseEvent is not a valid substitute for the bounded parameter <T extends Event> of the type EventHandler<T>
Bound mismatch: The type MouseEvent is not a valid substitute for the bounded parameter <T extends Event> of the type EventHandler<T>
MouseEvent cannot be resolved to a variable
MOUSE_CLICKED cannot be resolved to a variable
MouseEvent cannot be resolved to a variable
MOUSE_CLICKED cannot be resolved to a variable

at Main.start(Main.java:30)
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)
Exception running application Main
 
Das ist der Quellcode zu diesem Fehler

Java:
import java.awt.event.MouseEvent;

import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;

public class Main extends Application {

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

            Circle circle = new Circle(20);
            circle.setFill(Color.BLUE);
            circle.setTranslateX(200);
            circle.setTranslateY(200);

            Group root = new Group();
            root.getChildren().add(circle);

            Scene scene = new Scene(root, 400, 400);
            scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
            primaryStage.setScene(scene);
            primaryStage.show();

            EventHandler<MouseEvent> eventhandler1 = new EventHandler<MouseEvent>() {

                @Override
                public void handle(MouseEvent event) {
                    circle.setFill(Color.RED);
                    System.out.println("Filter aufgerufen");
                }
            };

            EventHandler<MouseEvent> eventhandler2 = new EventHandler<MouseEvent>() {

                @Override
                public void handle(MouseEvent event) {
                    circle.setScaleX(2);
                    circle.setScaleY(2);
                    System.out.println("Händler aufgerufen");
                }
            };
            
            circle.addEventFilter(MouseEvent, MOUSE_CLICKED, eventhandler1);
            circle.addEventHandler(MouseEvent, MOUSE_CLICKED, eventhandler2);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        launch(args);

    }

}



Hallo,
mir wird dieser Fehler angezeigt. Was habe ich falsch gemacht ?

Java:
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.Error: Unresolved compilation problems:
Bound mismatch: The type MouseEvent is not a valid substitute for the bounded parameter <T extends Event> of the type EventHandler<T>
Bound mismatch: The type MouseEvent is not a valid substitute for the bounded parameter <T extends Event> of the type EventHandler<T>
Bound mismatch: The type MouseEvent is not a valid substitute for the bounded parameter <T extends Event> of the type EventHandler<T>
Bound mismatch: The type MouseEvent is not a valid substitute for the bounded parameter <T extends Event> of the type EventHandler<T>
MouseEvent cannot be resolved to a variable
MOUSE_CLICKED cannot be resolved to a variable
MouseEvent cannot be resolved to a variable
MOUSE_CLICKED cannot be resolved to a variable

at Main.start(Main.java:30)
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)
Exception running application Main
 
Du hast das falsche `MouseEvent` import. java.awt.event.MouseEvent. Du brauchst `javafx.scene.input.MouseEvent{/iCode]
 

Zurück
Oben