Datenbank Choicebox wird nicht befüllt

Zakon

Bekanntes Mitglied
Hallo ich möchte für meine Datenbank mit JavaFX eine Choicebox einfügen. Problem nur obwohl ich meine alles richtig geschirben habe befüllt der diese nicht.
Java:
  private ObservableList<String> listefirma = FXCollections.observableArrayList("IT-Schmidt","IT-Larsen","Autohaus Krueger");


@FXML
    private ChoiceBox<String> boxFirma = new ChoiceBox<>();


@FXML
    public void dropdownFirmen (ActionEvent event){
        Connection conn = DBConnection.getInstance().getCon();
        boxFirma.getItems().addAll(listefirma);
        String auswahlFirma = boxFirma.getValue();
        try{
            dataall=FXCollections.observableArrayList();
            ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM Frimen F JOIN Mitarbeiter M ON F.ID=M.Firmen_ID " +
                    "JOIN Produkte P ON P.ID=M.ID WHERE F.Name IS LIKE '%"+auswahlFirma+"%'");
            while (rs.next()){
                dataall.add(new allDetails(rs.getInt(1),rs.getString(2),rs.getInt(3),rs.getString(4),
                        rs.getString(5),rs.getInt(6),rs.getInt(7),rs.getString(8)));
            }
            rs.close();

            if (conn != null && conn.isClosed()) {
                System.out.println("Connected");
            } else {
                System.out.println("Connection lost");
            }
        }catch(Exception e){
            System.out.println(e.fillInStackTrace());
        }
Wenn ich das Programm starte bekomme ich keine Fehlermeldung. Nur im Debugger bekomme ich etwas Rot angezeigt mit :"SorceCode does not match Bytecode". Das Programm selbst funktioniert aber nur meine Coicebox wird nicht ausgefüllt.

Danke im Vorraus für eure Hilfe 🙂
 
Hallo ich möchte für meine Datenbank mit JavaFX eine Choicebox einfügen. Problem nur obwohl ich meine alles richtig geschirben habe befüllt der diese nicht.
Java:
  private ObservableList<String> listefirma = FXCollections.observableArrayList("IT-Schmidt","IT-Larsen","Autohaus Krueger");


@FXML
    private ChoiceBox<String> boxFirma = new ChoiceBox<>();


@FXML
    public void dropdownFirmen (ActionEvent event){
        Connection conn = DBConnection.getInstance().getCon();
        boxFirma.getItems().addAll(listefirma);
        String auswahlFirma = boxFirma.getValue();
        try{
            dataall=FXCollections.observableArrayList();
            ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM Frimen F JOIN Mitarbeiter M ON F.ID=M.Firmen_ID " +
                    "JOIN Produkte P ON P.ID=M.ID WHERE F.Name IS LIKE '%"+auswahlFirma+"%'");
            while (rs.next()){
                dataall.add(new allDetails(rs.getInt(1),rs.getString(2),rs.getInt(3),rs.getString(4),
                        rs.getString(5),rs.getInt(6),rs.getInt(7),rs.getString(8)));
            }
            rs.close();

            if (conn != null && conn.isClosed()) {
                System.out.println("Connected");
            } else {
                System.out.println("Connection lost");
            }
        }catch(Exception e){
            System.out.println(e.fillInStackTrace());
        }
Wenn ich das Programm starte bekomme ich keine Fehlermeldung. Nur im Debugger bekomme ich etwas Rot angezeigt mit :"SorceCode does not match Bytecode". Das Programm selbst funktioniert aber nur meine Coicebox wird nicht ausgefüllt.

Danke im Vorraus für eure Hilfe 🙂
Wenn du ans Ende debuggst was kommt als Ergebnis für dataall raus? Enthält diese Liste Inhalt?
 
Das Problem ist wenn ich im Debugger bin dann komme ich nicht über diesen Punkt hinaus mit der oben gennanten Fehlermeldung 🤔
Java:
 private <T> T loadImpl(InputStream var1, Class<?> var2) throws IOException {
        if (var1 == null) {
            throw new NullPointerException("inputStream is null.");
        } else {
            this.callerClass = var2;
            this.controllerAccessor.setCallerClass(var2);

            try {
                this.clearImports();
                this.namespace.put("location", this.location);
                this.namespace.put("resources", this.resources);
                this.scriptEngine = null;

                try {
                    XMLInputFactory var3 = XMLInputFactory.newInstance();
                    var3.setProperty("javax.xml.stream.isCoalescing", true);
                    InputStreamReader var4 = new InputStreamReader(var1, this.charset);
                    this.xmlStreamReader = new StreamReaderDelegate(var3.createXMLStreamReader(var4)) {
                        public String getPrefix() {
                            String var1 = super.getPrefix();
                            if (var1 != null && var1.length() == 0) {
                                var1 = null;
                            }

                            return var1;
                        }

                        public String getAttributePrefix(int var1) {
                            String var2 = super.getAttributePrefix(var1);
                            if (var2 != null && var2.length() == 0) {
                                var2 = null;
                            }

                            return var2;
                        }
                    };
                } catch (XMLStreamException var16) {
                    throw this.constructLoadException((Throwable)var16);
                }

                this.loaders.push(this);

                try {
                    while(this.xmlStreamReader.hasNext()) {
                        int var21 = this.xmlStreamReader.next();
                        switch(var21) {
                        case 1:
                            this.processStartElement();
                            break;
                        case 2:
                            this.processEndElement();
                            break;
                        case 3:
                            this.processProcessingInstruction();
                            break;
                        case 4:
                            this.processCharacters();
                            break;
                        case 5:
                            this.processComment();
                        }
                    }
                } catch (XMLStreamException var17) {
                    throw this.constructLoadException((Throwable)var17);
                }

                if (this.controller != null) {
                    if (this.controller instanceof Initializable) {
                        ((Initializable)this.controller).initialize(this.location, this.resources);
                    } else {
                        Map var22 = this.controllerAccessor.getControllerFields();
                        this.injectFields("location", this.location);
                        this.injectFields("resources", this.resources);
                        Method var23 = (Method)((Map)this.controllerAccessor.getControllerMethods().get(FXMLLoader.SupportedType.PARAMETERLESS)).get("initialize");
                        if (var23 != null) {
                            try {
                                MethodHelper.invoke(var23, this.controller, new Object[0]);
                            } catch (IllegalAccessException var14) {
                                throw this.constructLoadException((Throwable)var14);
                            } catch (InvocationTargetException var15) {
                                throw this.constructLoadException((Throwable)var15);
                            }
                        }
                    }
                }
            } catch (LoadException var18) {
                throw var18;
            } catch (Exception var19) {
                throw this.constructLoadException((Throwable)var19);
            } finally {
                this.controllerAccessor.setCallerClass((Class)null);
                this.controllerAccessor.reset();
                this.xmlStreamReader = null;
            }

            return this.root;
        }
    }
Das ist die FXMLLoader.class
 
Das Problem ist wenn ich im Debugger bin dann komme ich nicht über diesen Punkt hinaus mit der oben gennanten Fehlermeldung 🤔
Java:
 private <T> T loadImpl(InputStream var1, Class<?> var2) throws IOException {
        if (var1 == null) {
            throw new NullPointerException("inputStream is null.");
        } else {
            this.callerClass = var2;
            this.controllerAccessor.setCallerClass(var2);

            try {
                this.clearImports();
                this.namespace.put("location", this.location);
                this.namespace.put("resources", this.resources);
                this.scriptEngine = null;

                try {
                    XMLInputFactory var3 = XMLInputFactory.newInstance();
                    var3.setProperty("javax.xml.stream.isCoalescing", true);
                    InputStreamReader var4 = new InputStreamReader(var1, this.charset);
                    this.xmlStreamReader = new StreamReaderDelegate(var3.createXMLStreamReader(var4)) {
                        public String getPrefix() {
                            String var1 = super.getPrefix();
                            if (var1 != null && var1.length() == 0) {
                                var1 = null;
                            }

                            return var1;
                        }

                        public String getAttributePrefix(int var1) {
                            String var2 = super.getAttributePrefix(var1);
                            if (var2 != null && var2.length() == 0) {
                                var2 = null;
                            }

                            return var2;
                        }
                    };
                } catch (XMLStreamException var16) {
                    throw this.constructLoadException((Throwable)var16);
                }

                this.loaders.push(this);

                try {
                    while(this.xmlStreamReader.hasNext()) {
                        int var21 = this.xmlStreamReader.next();
                        switch(var21) {
                        case 1:
                            this.processStartElement();
                            break;
                        case 2:
                            this.processEndElement();
                            break;
                        case 3:
                            this.processProcessingInstruction();
                            break;
                        case 4:
                            this.processCharacters();
                            break;
                        case 5:
                            this.processComment();
                        }
                    }
                } catch (XMLStreamException var17) {
                    throw this.constructLoadException((Throwable)var17);
                }

                if (this.controller != null) {
                    if (this.controller instanceof Initializable) {
                        ((Initializable)this.controller).initialize(this.location, this.resources);
                    } else {
                        Map var22 = this.controllerAccessor.getControllerFields();
                        this.injectFields("location", this.location);
                        this.injectFields("resources", this.resources);
                        Method var23 = (Method)((Map)this.controllerAccessor.getControllerMethods().get(FXMLLoader.SupportedType.PARAMETERLESS)).get("initialize");
                        if (var23 != null) {
                            try {
                                MethodHelper.invoke(var23, this.controller, new Object[0]);
                            } catch (IllegalAccessException var14) {
                                throw this.constructLoadException((Throwable)var14);
                            } catch (InvocationTargetException var15) {
                                throw this.constructLoadException((Throwable)var15);
                            }
                        }
                    }
                }
            } catch (LoadException var18) {
                throw var18;
            } catch (Exception var19) {
                throw this.constructLoadException((Throwable)var19);
            } finally {
                this.controllerAccessor.setCallerClass((Class)null);
                this.controllerAccessor.reset();
                this.xmlStreamReader = null;
            }

            return this.root;
        }
    }
Das ist die FXMLLoader.class
Hast du ein Problem mit dem Laden der Fxml? Was ist die genaue Excecption?
 
Hallo ich möchte für meine Datenbank mit JavaFX eine Choicebox einfügen. Problem nur obwohl ich meine alles richtig geschirben habe befüllt der diese nicht.
Java:
  private ObservableList<String> listefirma = FXCollections.observableArrayList("IT-Schmidt","IT-Larsen","Autohaus Krueger");


@FXML
    private ChoiceBox<String> boxFirma = new ChoiceBox<>();


@FXML
    public void dropdownFirmen (ActionEvent event){
        Connection conn = DBConnection.getInstance().getCon();
        boxFirma.getItems().addAll(listefirma);
        String auswahlFirma = boxFirma.getValue();
        try{
            dataall=FXCollections.observableArrayList();
            ResultSet rs = conn.createStatement().executeQuery("SELECT * FROM Frimen F JOIN Mitarbeiter M ON F.ID=M.Firmen_ID " +
                    "JOIN Produkte P ON P.ID=M.ID WHERE F.Name IS LIKE '%"+auswahlFirma+"%'");
            while (rs.next()){
                dataall.add(new allDetails(rs.getInt(1),rs.getString(2),rs.getInt(3),rs.getString(4),
                        rs.getString(5),rs.getInt(6),rs.getInt(7),rs.getString(8)));
            }
            rs.close();

            if (conn != null && conn.isClosed()) {
                System.out.println("Connected");
            } else {
                System.out.println("Connection lost");
            }
        }catch(Exception e){
            System.out.println(e.fillInStackTrace());
        }
Wenn ich das Programm starte bekomme ich keine Fehlermeldung. Nur im Debugger bekomme ich etwas Rot angezeigt mit :"SorceCode does not match Bytecode". Das Programm selbst funktioniert aber nur meine Coicebox wird nicht ausgefüllt.

Danke im Vorraus für eure Hilfe 🙂
Bezüglich "SourceCode does not match", versuch das Projekt erneut zu bauen, siehe hier https://stackoverflow.com/questions...match-the-bytecode-when-debugging-on-a-device
 
Das Programm startet ganz Normal und die FXML lädt meines Wissens auch normal bekomme im Debugger nur die Info: Variables debug info not available und die oben gennante Fehlermeldung
 
Java:
public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("view.fxml"));
        primaryStage.setTitle("Datenbank Firmen");
        primaryStage.setScene(new Scene(root, 800, 600));
        primaryStage.show();

    }

    @Override
    public void stop() throws Exception {
        DBConnection.getInstance().getCon().close();
        super.stop();
    }

    @Override
    public void init() throws Exception {
        DBConnection.getInstance().connect();
        super.init();
    }

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

Ich denke mal du meinst diesen Abschnitt wo der oben die FXML lädt.
Und ja es wird alles angezeigt und das Programm läuft auch wenn ich es Ausführe. Das einzige Problem ist das meine CoiceBox leer ist.
 
Jetzt habe ich das ganze neu aufgesetzt und jetzt bekomme ich eine Exception running Application Main.Main obwohl es ja quasi das selbe ist 🙄
Java:
package Main;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("view.fxml"));
        primaryStage.setTitle("Datenbank Firmen");
        primaryStage.setScene(new Scene(root, 800, 600));
        primaryStage.show();
    }

    @Override
    public void stop() throws Exception {
        DBConnection.getInstance().getCon().close();
        super.stop();
    }

    @Override
    public void init() throws Exception {
        DBConnection.getInstance().connect();
        super.init();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
 
Ist
Jetzt habe ich das ganze neu aufgesetzt und jetzt bekomme ich eine Exception running Application Main.Main obwohl es ja quasi das selbe ist 🙄
Java:
package Main;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("view.fxml"));
        primaryStage.setTitle("Datenbank Firmen");
        primaryStage.setScene(new Scene(root, 800, 600));
        primaryStage.show();
    }

    @Override
    public void stop() throws Exception {
        DBConnection.getInstance().getCon().close();
        super.stop();
    }

    @Override
    public void init() throws Exception {
        DBConnection.getInstance().connect();
        super.init();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
Kannst du bitte StackTrace hierein pasten?
 
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:566)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
    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:566)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module @0x110ad01a) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module @0x110ad01a
    at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
    at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2138)
    at Main.Main.start(Main.java:15)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    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:174)
    ... 1 more
Exception running application Main.Main

Process finished with exit code 1

habe eine Exception in der Start Method kann aber nicht verstehen warum
 
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:566)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
    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:566)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module @0x110ad01a) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module @0x110ad01a
    at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
    at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2138)
    at Main.Main.start(Main.java:15)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    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:174)
    ... 1 more
Exception running application Main.Main

Process finished with exit code 1

habe eine Exception in der Start Method kann aber nicht verstehen warum
Ach du bist schon bei OpenJFX. Ich kenne mich da leider noch viel zu wenig aus. Aber der Fehlermeldung nach kannst du nicht auf diese Klasse zugreifen cannot access class com.sun.javafx.util.Utils. Vermutlich muss du in der module.info noch ein weiterer Import machen, damit dein Projekt darauf zugreifen kann.

@dzim kannst du da weiterhelfen, du hast mit OpenJFX schon mehr Erfahrung.
 
Meine Empfehlung ist, auch direkt mit Modulen zu arbeiten, wenn man Java 8 verlässt.

Es könnte schon ausreichen, eine module-info.java hinzu zu fügen a.la.
Java:
module mymodule {
    requires javafx.controls;
    requires javafx.graphics;
    requires javafx.fxml;
    opens mymodule;
}

Natürlich ggf. noch etwas weiter angepasst wenn notwendig.
 
Ok ich werde mir dazu mal ein paar saschen angucken und durchlesen. Bis jetzt waren mir Module noch nicht bekannt aber danke 🙂
 
Also ein Link, der evtl. für einen schnellen Überblick taugen könnte:

Und da wird die Problematik auch schnell deutlich wenn man Tabelle 3 betrachtet:
Das unnamed Module hat ein automatisches read auf alle vorhandenen Module im ClassPath und exportiert alle Inhalte.

Das reicht aber hier nicht aus, denn JavaFX möchte per Deep Reflection(*) auf die Klassen zugreifen. Das setzt aber ein open module voraus.

Das, was hier aber auch noch alternativ denkbar wäre, wäre das bauen eines Automatic Module - das bekommt man, wenn man ein jar file ohne jegliche Modul-Spezifikationen baut. Da wäre dieses Deep Reflection auch möglich. Wenn es auf irgend welche Wege auch funktioniert hat, dann sehe ich da zwei Optionen: a) Java 8 wurde da verwendet b) es wurde über eine Art Automatic Module gearbeitet.

Aber meine Meinung ist halt: Wenn das unnamed module nicht ausreicht, dann wird es Zeit, sich mit den Modulen zu beschäftigen 🙂

(*) Deep Reflection ist als Begriff evtl. unüblich. In dem Link wird dies klar definiert: "Deep Reflection bedeutet, dass ein Zugriff per Reflection auf einen Typ durchgeführt wird, der eigentlich nicht zugreifbar ist, zum Beispiel weil er private oder protected ist. Dies war bis Java8 durch setAccessible(true) möglich und ist nun nicht mehr per se erlaubt."
Und genau das macht ja z.B. der FXMLLoader, wenn er auf private Instanzvariablen zugreift, die eine @FXML Annotation haben.
 
Zum neuen jahr dann auch gleichmal einen Fehler behoben.
Das Problem war eigentlich nur das ich an der Stelle wo ich die Choicebox befülle garnicht vorbei gekommen bin.
haben jetzt oben eine Initzialiesierungs klasse geschireben und jetzt funkrioniert alles 🙄
Danke Trozdem für eure Hilfe 👍

Java:
public void initialize() {
        boxFirma.setItems(listefirma);
        boxProdukt.setItems(listeprodukt);
        boxName.setItems(listename);
    }
 

Zurück
Oben