早上好,我对java很陌生,遇到了一个问题。我正在构建一个基于朋友的代码的tableView,但是当我尝试这样做的时候,我会得到错误"Error:java.lang.RuntimeException: Exception in Application方法“--只有当我有下面的代码时才会发生。如果我删除它,应用程序就会运行。
主要班:
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;
}
}堆栈跟踪
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发布于 2022-05-09 09:31:58
com.mysql.jdbc.Driver‘。这是不可取的。新的驱动程序类是com.mysql.cj.jdbc.Driver‘
您需要在应用程序中更改jdbc (DataBase配置)。搜索字符串类型:"com.mysql.jdbc.Driver“,并尝试将其更改为"com.mysql.cj.jdbc.Driver”。
https://stackoverflow.com/questions/72169261
复制相似问题