0

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.

error page navigation when using new constructor

Mark Rotteveel
  • 90,369
  • 161
  • 124
  • 175
Lakshan
  • 19
  • 1
  • 4
  • Your classpath at runtime is not including all cases that were available at compile time. You need to find out why. – swpalmer Jan 25 '22 at 16:07
  • tnx @swpalmer : ) I will look into that. – Lakshan Jan 26 '22 at 16:17
  • I search about wt u said & found a relevant answer for my problem [link](https://stackoverflow.com/questions/4270950/compile-time-vs-run-time-dependency-java). After going through several answers I understood that JVM executes the code with limitations in order to save memory & time or necessity (correct me if I understood this wrong. I'm still a Java beginner). Thanks to that I came up with an idea to put the **navigation-constructor part (line no:252,253)** inside of a function inside the package class & it worked. I sense that this isn't a better solution but is it okay to do so? – Lakshan Jan 26 '22 at 17:48
  • Too hard to tell without seeing much more of the project structure. – swpalmer Jan 27 '22 at 13:01
  • Here, I uploaded the current code set into my [Github](https://github.com/M-lakshan/DiSE-ChemMovers_v1_0/tree/guest_1) I appreciate your help :) tnx Mr.@swpalmer – Lakshan Jan 27 '22 at 17:41

0 Answers0