| Author |
Email: java.lang.ClassFormatError
|
Lila Fowler
Ranch Hand
Joined: Jul 31, 2009
Posts: 73
|
|
Hi all,
I am trying to send a simple email from a java application (not a ee application), I am using NetBeans and have imported the:
"Java EE 6 API Library - javaee-api-6.0.jar" - located in the NetBeans sub-folder
"javaee.jar" - located in the glassfish lib folder
Netbeans found no syntax errors and all the imports where excepted once I had added the above files.
But when i run the program I get the following exception:
run:
java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/mail/Address
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: linxaslicencemanagment.MailClient. Program will exit.
Exception in thread "main" Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
Any ideas as to what can be causing this or how I am able to solve this?
All the google-ing i did on the exception told me that adding the library was not enough
as it didn't actually have those classes/methods and that I had to add the .jar as well.
But the exception hasn't changed.
Here is the code:
Any Ideas as to what I am doing incorrectly?
Thanks
|
Courage is not the absence of fear but rather the judgment that something is more important then fear. ~ Ambrose Redmond
|
 |
Lila Fowler
Ranch Hand
Joined: Jul 31, 2009
Posts: 73
|
|
Update:
Added the javax.mail.jar to my lib but am still getting the same exception.
Any Ideas?
Thanks
|
 |
Saikat Roy Mahasay
Greenhorn
Joined: Jan 12, 2012
Posts: 10
|
|
|
Did you try it outside NetBeans ? I tried to copy-paste and run your code in eclipse, and it sort of worked. At least I didn't get the ClassFormatError. I used java 1.6 and javamail-1.4.2.
|
 |
Lila Fowler
Ranch Hand
Joined: Jul 31, 2009
Posts: 73
|
|
Thanks Saikat,
That exception does disappear when I use it in Eclipse and not NetBeans? - weird.
I added a few changes for the errors I was getting now its getting to a part of the code and just stopping.
I'v waited 30min and it doesn't move on or return any exceptions or errors.
Decided to try get gmail working correctly first.
Any ideas as to what I am doing incorrectly?
Code is the same as above with edited code below. //16 = line changed
Thanks.
|
 |
Lila Fowler
Ranch Hand
Joined: Jul 31, 2009
Posts: 73
|
|
Update:
After about 2hours I got the following exception:
javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465, response: -1
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1922)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
at javax.mail.Service.connect(Service.java:295)
at linxaslicencemanagment.MailClient.sendMail(MailClient.java:45)
at linxaslicencemanagment.MailClient.main(MailClient.java:83)
|
 |
Lila Fowler
Ranch Hand
Joined: Jul 31, 2009
Posts: 73
|
|
Final working code for future reference if anyone may need it:
|
 |
 |
|
|
subject: Email: java.lang.ClassFormatError
|
|
|