Ошибка при инициализации загрузочного слоя к модулю javafx.swt
Здравствуйте, мой проект находится в затмении. Я пытаюсь создать панель регистрации в javafx Scenebuilder, в которую я получаю информацию (идентификатор, имя, пароль, номер кредитной карты ...) ) от пользователя с помощью GUI и последующей вставки учетной записи в базу данных MySQL (phpmyadmin), но я получаю сообщение об ошибке. мой код: F XML файл:
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.text.Text;
public class RegisterController {
@FXML
private PasswordField PasswordTxt;
@FXML
private TextField NameText;
@FXML
private TextField CreditCardText;
@FXML
private Button SubmitBtn;
@FXML
private Text errorTXT;
@FXML
private TextField IDText;
@FXML
void addAccount(ActionEvent event) {
}
}
Класс контроллера:
import connection.Account;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.PasswordField;
import javafx.scene.control.TextField;
import javafx.scene.text.Text;
public class RegisterController {
@FXML
private PasswordField PasswordTxt;
@FXML
private TextField NameText;
@FXML
private TextField CreditCardText;
@FXML
private Button SubmitBtn;
@FXML
private Text errorTXT;
@FXML
private TextField IDText;
@FXML
void addAccount(ActionEvent event) throws Exception {
String name=NameText.getText();
String password=PasswordTxt.getText();
String id=IDText.getText();
String visa=CreditCardText.getText();
Account acc=new Account(name,password,id,visa);
acc.Register(acc);
}
}
Основной класс:
import java.io.IOException;
import java.net.URL;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
public class RegisterGUI extends Application {
@Override
public void start(Stage primaryStage) throws IOException{
URL url = getClass().getResource("RegisterGUI.fxml");
AnchorPane pane = FXMLLoader.load(url);
Scene scene = new Scene (pane);
//setting the stage
primaryStage.setScene(scene);
primaryStage.setTitle("Register");
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
} ```
*Account Class:*
``` package connection;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import DB.DB;
public class Account {
private int AccountNum;
private String Name;
private String Password;
private String ID;
private String Visa;
private int Permission;
public Account(String name, String pass, String id, String visa) throws SQLException {
this.Name=name;
this.ID=id;
this.Password=pass;
this.Permission=4;
this.Visa=visa;
Connection con;
try {
con = DB.getInstance().getConnection();
Statement stmt = con.createStatement();
String sql="SELECT MAX(AccountNum) FROM Account";
ResultSet rs=stmt.executeQuery(sql);
while(rs.next()){
this.AccountNum=(rs.getInt("MAX(AccountNum)"))+1;
}
rs.close();
stmt.close();
con.close();
} catch(SQLException s){
s.printStackTrace();
}
}
public void Register(Account acc) throws Exception
{
Connection con;
try {
if(acc.Name.length() > 20 || acc.Name.length()==0)
throw new Exception("name length is invalid");
if(acc.Password.length()>20 || acc.Password.length()==0)
throw new Exception("password length is invalid");
if(acc.ID.length()!=9)
throw new Exception("ID is invalid");
if(acc.Visa.length()!=19)
throw new Exception("Credit card number is invalid");
for(int i=0;i<acc.ID.length();i++)
{if(acc.ID.charAt(i) < '0'|| acc.ID.charAt(i) > '9')
throw new Exception("ID should be made of numbers only");}
for(int i=0;i<acc.Visa.length();i++)
{if((acc.Visa.charAt(i) < '0'|| acc.Visa.charAt(i) > '9') && acc.Visa.charAt(i)!=' ')
throw new Exception("Credit card should be made of numbers only");}
con = DB.getInstance().getConnection();
String sql="INSERT INTO `Account` "+"(AccountNum,ID,Name,Password,Visa,Permission,Refund)"
+"VALUES (?, ?, ?, ?, ?, ?, ?)";
PreparedStatement preparedStmt = con.prepareStatement(sql);
preparedStmt.setInt (1, acc.AccountNum);
preparedStmt.setString (2,acc.ID);
preparedStmt.setString (3, acc.Name);
preparedStmt.setString(4, acc.Password);
preparedStmt.setString (5,acc.Visa);
preparedStmt.setInt(6, acc.Permission);
preparedStmt.setInt(7,0);
preparedStmt.execute();
con.close();
}catch (SQLException e) {
e.printStackTrace();
}
}
public boolean Login(String Name,String Password) throws SQLException
{
Connection con;
PreparedStatement prep_stmt=null;
try {
con = DB.getInstance().getConnection();
String sql="SELECT * FROM `Account`";
prep_stmt=con.prepareStatement(sql);
ResultSet rs=prep_stmt.executeQuery(sql);
while(rs.next())
{
String name=rs.getString("Name");
String pass=rs.getString("Password");
if(name.equals(Name)&& pass.equals(Password)) {
System.out.println("Logged in Successfully!!");
return true;
}
}
rs.close();
prep_stmt.close();
con.close();
}catch (SQLException e) {
e.printStackTrace();
}
System.out.println("Name or Password is incorrect");
return false;
}
public boolean hasPermission(Account acc,String op)
{
if(acc.Permission<=2)
return true;
if( (acc.Permission<=3 && op.equals("Update Item")))
return true;
if(acc.Permission==4 && op.equals("Complaint Handle"))
return true;
return false;
}
}
Класс БД:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class DB {
static private final String JDBC_DRIVER = "com.mysql.cj.jdbc.Driver";
// update USER, PASS and DB URL according to credentials provided by the website:
// https://remotemysql.com/
// in future move these hard coded strings into separated config file or even better env variables
static private final String DB = "1qwLK4HUCz";
static private final String DB_URL = "jdbc:mysql://remotemysql.com/"+ DB + "?useSSL=false";
static private final String USER = "1qwLK4HUCz";
static private final String PASS = "********";
private static DB instance=null;
private DB() {
try {
Class.forName(JDBC_DRIVER);
System.out.println("Database(): MySQL driver loaded");
} catch (ClassNotFoundException e) {
System.out.println("Database(): MySQL driver failed to load\n" + e.getMessage());
System.exit(0);
}
}
public static DB getInstance() {
if (instance == null) {
instance = new DB();
}
return instance;
}
public Connection getConnection() throws SQLException {
return DriverManager.getConnection(DB_URL, USER, PASS);
}
}
пароль скрыт для безопасности, но его право.
аргументы моей виртуальной машины для основного: --module-path "C: \ javafx-sdk-13.0.1 \ lib" --add-modules javafx.controls, javafx.f xml