1

In my Java project, it used to work perfectly without any issue.

But when I tried to run it now, it gives me the following error. I googled it, but couldn't find a proper solution.

Below is my Java class:

public class MyClass{
    public static void main(String[] args) {
         try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (ClassNotFoundException ex) {java.util.logging.Logger.getLogger(Dashboard.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {java.util.logging.Logger.getLogger(Dashboard.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {java.util.logging.Logger.getLogger(Dashboard.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {java.util.logging.Logger.getLogger(Dashboard.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        DB.connect();
        Login login = new Login();
        login.setVisible(true);
    }
}

The error is:

Exception in thread "main" java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file mypackage/Login
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at mypackage.MyClass.main(MyClass.java:38)
Java Result: 1

If anybody knows the solution, please help me to solve this issue.

Thanks

alain.janinm
  • 19,951
  • 10
  • 65
  • 112
Mujahid
  • 1,227
  • 5
  • 32
  • 62

3 Answers3

2

Exception in thread "main" java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file mypackage/Login

This seems to indicate something is wrong with your Login class - possibly unimplemented method(s).

Raghuram
  • 51,854
  • 11
  • 110
  • 122
  • I'm curious how he get this compiled, but the problem also can be that the class is compiled with newer compiler that the JVM he is trying to run it on. – Rastislav Komara Nov 03 '11 at 16:41
1

I experienced the same problem. Actually it's was a Netbean issue for me...

Go in your project properties, then in Compiling disable Compile on Save. Clean and Build your project, then try to run it.

Other solution to try, take a look at your Source/Binary format in your project properties (sources), and make sure you use the right one. Check the JDK platform used by libraries too. I've update to JDK1.7(default) for libraries and JDK6 for source and then it works for me.

Other possible answers here :

  1. java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file "name of class"
  2. java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/faces/webapp/FacesServlet
Community
  • 1
  • 1
alain.janinm
  • 19,951
  • 10
  • 65
  • 112
0

check the package name on top. typo for "mypacakge"?

You Qi
  • 8,353
  • 8
  • 50
  • 68
  • Sorry it was my mistake when I put the question. Package names are ok, but still the error is there :( – Mujahid Nov 03 '11 at 11:13
  • Please edit your question to show the exact code you are trying to compile and say how you're compiling and run (i.e. exactly what commands, or if through an IDE, which IDE). – Simon Nickerson Nov 03 '11 at 11:20
  • Above shown is the exact code. I just only changed the package name and the class file names to update here. I am using NetBeans IDE 7.0.1 – Mujahid Nov 03 '11 at 11:24