I've created my first Java application for one of my university projects, and I'm currently stuck at navigating to the application main interface after validating login page inputs data with a relevant database. The validation part is done but the page-navigation method is not working inside my validation.
The project builds fine without any errors but I keep getting:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: Chem_Process/Dashbord
for the : Dashbord DashbordPage = new Dashbord(); DashbordPage.setVisible(true); constructor (this is fully functional in other parts in my code but not inside the login page).
However if I put this constructor inside a normal private void buttonActionPerformed(java.awt.event.ActionEvent evt) {} funtion this will work and navigate to the destination page without any errors.
Here is the code:
Connection con = null;
// check DB connection
public void sqlconncection() {
try {
con = DriverManager.getConnection("jdbc:mysql://localhost/chemmovers_v1_0","root","");
}
catch (SQLException e) {
System.out.println("Error: "+e);
}
}
// login btn actions
private void btn_loginActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String uname = cus_uname.getText();
String pwd = new String(cus_pwd.getPassword());
// match values with DB user details
sqlconncection();
Statement stm;
try {
stm = (Statement)con.createStatement();
String query = " SELECT * FROM `customer` WHERE cus_uname='"+uname+"';" ;
ResultSet result_set = stm.executeQuery(query);
while (result_set.next()) {
String db_uname = result_set.getString("cus_uname");
String db_u_pwd = result_set.getString("cus_pwd");
System.out.println(uname+" "+pwd);
System.out.println(db_uname+" "+db_u_pwd);
if(uname.equals(db_uname) && pwd.equals(db_u_pwd)) {
label_login_alert.setText("");
this.dispose();
Dashbord DashbordPage = new Dashbord();
DashbordPage.setVisible(true);
}
else {
label_login_alert.setText("Account doesn't exist or wrong user details!");
}
}
} catch (SQLException ex) {
Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
}
}
I want to know why I keep getting the 'java.lang.NoClassDefFoundError' but for this not for other normal button navigation. The button action function is shown in the link below.