-1

Morning all, I'm new to java and running into an issue. I'm building a tableView based on a friend's code which is working however when I try to do it I get the error "Error:java.lang.RuntimeException: Exception in Application start method" it only happens when I have the code below. If I deleted it, the application runs.

Main Class:

    TableView<tableClass> tableView = new TableView<tableClass>();

    ResultSet RtnRS = dataBase.GetCars();

    List<String> Registration = new ArrayList<String>();
    List<String> Manufacturer = new ArrayList<String>();
    List<String> Model = new ArrayList<String>();
    List<String> Engine = new ArrayList<String>();
    List<String> Description = new ArrayList<String>();
    List<String> Type = new ArrayList<String>();

    String RegOut = RtnRS.getString("registration");
    Registration.add(RegOut);
    String ManOut = RtnRS.getString("manufacturer");
    Manufacturer.add(ManOut);
    String ModOut = RtnRS.getString("model");
    Model.add(ModOut);
    String EngOut = RtnRS.getString("engine");
    Engine.add(EngOut);
    String DesOut = RtnRS.getString("description");
    Description.add(DesOut);
    String TypOut = RtnRS.getString("type");
    Type.add(TypOut);

    for (int i = 0; i < Registration.size();i++) {
        tableView.getItems().add(new tableClass(Registration.get(i), Manufacturer.get(i), Model.get(i), Engine.get(i), Description.get(i), Type.get(i)));
    }
             
    TableColumn<tableClass, String> column1 = new TableColumn<>("Registration");    
    column1.setCellValueFactory(new PropertyValueFactory<>("Registration"));
    TableColumn<tableClass, String> column2 = new TableColumn<>("Manufacturer");
    column2.setCellValueFactory(new PropertyValueFactory<>("Manufacturer"));
    TableColumn<tableClass, String> column3 = new TableColumn<>("Model");
    column3.setCellValueFactory(new PropertyValueFactory<>("Model"));
    TableColumn<tableClass, String> column4 = new TableColumn<>("Engine");
    column4.setCellValueFactory(new PropertyValueFactory<>("Engine"));
    TableColumn<tableClass, String> column5 = new TableColumn<>("Description");
    column5.setCellValueFactory(new PropertyValueFactory<>("Description"));
    TableColumn<tableClass, String> column6 = new TableColumn<>("Type");
    column5.setCellValueFactory(new PropertyValueFactory<>("Type"));

    // Add columns to table
    tableView.getColumns().add(column1);
    tableView.getColumns().add(column2);
    tableView.getColumns().add(column3);
    tableView.getColumns().add(column4);
    tableView.getColumns().add(column5);
    tableView.getColumns().add(column6);

tableClass:

public class tableClass {
    

private String Registration = null;
private String Manufacturer = null;
private String Model = null;
private String Engine = null;
private String Description = null;
private String Type = null;

public tableClass(String Registration, String Manufacturer, String Model, String Engine, String Description, String Type) {
    this.Registration = Registration;
    this.Manufacturer = Manufacturer;
    this.Model = Model;
    this.Engine = Engine;
    this.Description = Description;
    this.Type = Type;
}

public String getReg() {
    return Registration;
}

public void setReg(String Registration) {
    this.Registration = Registration;
}

public String getMan() {
    return Manufacturer;
}

public void setMan(String Manufacturer) {
    this.Manufacturer = Manufacturer;
}

public String getMod() {
    return Model;
}

public void setMod(String Model) {
    this.Model = Model;
}

public String getEng() {
    return Engine;
}

public void setEng(String Engine) {
    this.Engine = Engine;
}

public String getDes() {
    return Description;
}

public void setDes(String Description) {
    this.Description = Description;
}

public String getTyp() {
    return Type;
}

public void setTyp(String Type) {
    this.Type = Type;
}

}

Stack Trace

PS C:\Users\maxmc\OneDrive\Desktop\Mck Hire JavaFX\MckHireJavaFX>  c:; cd 'c:\Users\maxmc\OneDrive\Desktop\Mck Hire JavaFX\MckHireJavaFX'; & 'C:\Program Files\Eclipse Adoptium\jdk-17.0.2.8-hotspot\bin\java.exe' '--module-path' 'C:/Users/maxmc/OneDrive/Documents/openjfx-18_windows-x64_bin-sdk/javafx-sdk-18/lib' '--add-modules' 'javafx.controls,javafx.fxml' '-XX:+ShowCodeDetailsInExceptionMessages' '@C:\Users\maxmc\AppData\Local\Temp\cp_16o1mso8ggtiyi1capztdqsfl.argfile' 'App' 
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
Database is connected !Exception in Application start method
Do not connect to DB - Error:java.lang.RuntimeException: Exception in Application start method
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • 3
    Maybe you could show us the stacktrace? – Scary Wombat May 09 '22 at 08:52
  • 2
    You're leaving out the important parts of the error. Please [edit] your question to provide the entire [stack trace](https://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my-application-errors). – Slaw May 09 '22 at 08:57
  • @ScaryWombat i think i have added the stacktrace to original post now – Max Mckinnon May 09 '22 at 09:02
  • You haven't posted a stack trace. A stack trace has a lot of lines with the different methods calls that lead to an exception, and - optionally - the exception(s) that caused the final exception. – Mark Rotteveel May 09 '22 at 09:36
  • @MarkRotteveel im not sure how to find this – Max Mckinnon May 09 '22 at 09:39
  • 1
    Likely your code is currently printing out the exception now with `System.out.println(exception)` or something like that. Instead, use `exception.printStackTrace()`. – Mark Rotteveel May 09 '22 at 09:40
  • Even if you get past that exception, your table won’t show any data. The best way to address this is to [avoid using PropertyValueFactory](https://stackoverflow.com/questions/65785787/javafx-tableview-not-showing-data-something-wrong-with-getter-setters/65786210#65786210). – VGR May 09 '22 at 12:16
  • @VGR i would like to pursue this method, could you explain why it wouldnt show data? – Max Mckinnon May 09 '22 at 13:32
  • I did explain it, in that link. – VGR May 09 '22 at 13:33
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community May 09 '22 at 19:18

1 Answers1

-2

com.mysql.jdbc.Driver'. This is deprecated. The new driver class is com.mysql.cj.jdbc.Driver'

You need change jdbc config (DataBase config) in your app. Search for the String type: "com.mysql.jdbc.Driver" and try change it for "com.mysql.cj.jdbc.Driver".

Oleg
  • 22
  • 4
  • 2
    That is just a *warning* reported when you load the old `com.mysql.jdbc.Driver` class instead of the new one. The driver is still loaded properly, so it is not the problem the OP seems to be asking about (the _"Do not connect to DB - Error:java.lang.RuntimeException: Exception in Application start method"_). – Mark Rotteveel May 09 '22 at 09:35
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 09 '22 at 18:39