0

Exception in thread "main" java.lang.NoClassDefFoundError: org/netbeans/lib/awtextra/AbsoluteLayout

at ApplicationPackage.StartPage.initComponents(StartPage.java:300)
at ApplicationPackage.StartPage.<init>(StartPage.java:57)
at ApplicationPackage.Main.main(Main.java:30)

Caused by: java.lang.ClassNotFoundException: org.netbeans.lib.awtextra.AbsoluteLayout

at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more

My code:

try {

 UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
    } 
    catch (UnsupportedLookAndFeelException | ClassNotFoundException | InstantiationException | IllegalAccessException e) {
        JOptionPane.showMessageDialog(null, e.toString(), "Eroare la aplicarea stilului ferestrei", JOptionPane.ERROR_MESSAGE);
    }

    StartPage frame = new StartPage();
    frame.setVisible(true);      

How to solve this ?

Update: I solve this error. But now a have another question. How I can create a jar file with is in dependencies with a database ? My app write and read from a H2 database file.

Nicolae
  • 13
  • 7

2 Answers2

0

NoClassDefFoundError generally means the class isn't found on the classpath.

Here's some simple steps and things to look for (Using Netbeans).

  • When you add the library take these steps

    1. Right click on the [Library] node in the project from the [Projects] explorer tab.
    2. Select [Add Library]. AbsoluteLayout should be the first one.

  • Build you project. All the libraries should be exported to the [lib] folder, if you haven't changed any default build settings. Then you need to check a couple things:

    1. Check to make sure the library is actually there. Go to the [Files] tab (if it's not open, go to [Window]->[Files]) and make sure the library is in the [libs] dir:

      enter image description here

    2. Then check to make sure the library is on the classpath. Check the MANIFIEST.MF.

      enter image description here

      You should see the libs\AbsuluteLayout.jar on the classapth

      Manifest-Version: 1.0
      Ant-Version: Apache Ant 1.9.2
      Created-By: 1.8.0_20-b26 (Oracle Corporation)
      Class-Path: lib/AbsoluteLayout.jar
      X-COMMENT: Main-Class will be added automatically by build
      Main-Class: addjardemo.AddJarDemo

If all this is correct, what this means is that when you run your jar, the jar should be on the same level as the [lib] directory, as the application is dependent on that jar in that exact location (relative to the calling jar). Note: this is not the only way though. For more information, I'd do some research on "classpath"

If you want all the classes included into your jar, you will need to build an "Uber Jar". Not sure how to do this with Netbeans settings (if its even possible), but you can search for similar topics, like this one

Community
  • 1
  • 1
Paul Samsotha
  • 188,774
  • 31
  • 430
  • 651
  • thanks, I solve this error. But now a have another question. How I can create a jar file with is in dependencies with a database ? My app write and read from a H2 database file. – Nicolae Sep 07 '14 at 14:37
  • Do you have the H2 jar? Just do the same thing as with the AbsolutLayout jar, but instead when you right click on the Library node, select Add Jar. – Paul Samsotha Sep 07 '14 at 14:41
  • What do you expect me to do with that image? – Paul Samsotha Sep 07 '14 at 15:13
  • this is my class to conect http://i.imgur.com/vjfiBAu.png this is the frame to be opened http://i.imgur.com/6vBRnlL.png this is the error http://i.imgur.com/KVv9BbB.png after building I can't acces the databse – Nicolae Sep 07 '14 at 15:17
  • You really need to learn how to debug NullPointerExceptions. Read [What is a Null Pointer Exception, and how do I fix it?](http://stackoverflow.com/questions/218384/what-is-a-null-pointer-exception-and-how-do-i-fix-it). No one can help you debug this will images and no code. Sorry. If you want to share any code, POST the CODE, not images of exception. And copy and paste the stack trace – Paul Samsotha Sep 07 '14 at 15:31
  • but why in netbeans all works fine, and after build and clean doesn't work – Nicolae Sep 07 '14 at 15:37
  • What is line 27 that is throwing the exception? Look there – Paul Samsotha Sep 07 '14 at 15:41
  • it seems I solved the problem with the exceptions from command line, but after I make the .exe with LaunchJ again I obtain these exceptions – Nicolae Sep 07 '14 at 19:20
0

this is my function to get data from db

 public Vector getData(String query)throws Exception
    {
        Vector<Vector<String>> dataVector = new Vector<>();

        try (Connection myConnection = ConectDataBase.ConectToBD()) {
            PreparedStatement pst = myConnection.prepareStatement(query);
            ResultSet rs = pst.executeQuery();

            while(rs.next())
            {
                Vector<String> films = new Vector<>();
                films.add(rs.getString(1)); 
                films.add(rs.getString(2)); 
                films.add(rs.getString(3)); 
                films.add(rs.getString(4)); 
                films.add(rs.getString(5));
                films.add(rs.getString(6));
                films.add(rs.getString(7));
                films.add(rs.getString(8));
                films.add(rs.getString(9));
                dataVector.add(films);
            }
        }
        return dataVector;
    }

this is in the frame which contains the extracdet data

public ListOfFilms() throws Exception {

        // extragerea datelor din baza de date
        PopulateDataTable dbengine = new PopulateDataTable();
        data = dbengine.getData("SELECT * FROM DataStructure ORDER BY id DESC");
        initComponents();

}

this is my class to connect to db

public class ConectDataBase {

Connection myConnection;

public static Connection ConectToBD(){

    try {
        Class.forName("org.h2.Driver");
        Connection myConnection = DriverManager.getConnection("jdbc:h2:~//RatedMovies", "", "");

        return myConnection;
    }
    catch (ClassNotFoundException | SQLException e)
    {
        return null;
    }                     
}

}

Nicolae
  • 13
  • 7