• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Email: java.lang.ClassFormatError

 
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Lila Fowler
Ranch Hand
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Update:
Added the javax.mail.jar to my lib but am still getting the same exception.

Any Ideas?
Thanks
 
Greenhorn
Posts: 10
Opera VI Editor Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 90
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Final working code for future reference if anyone may need it:

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I tried your final code in Eclips and i still get the following error could anyone help me with it:

java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/mail/BodyPart
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)


Here is the code i tried:

import java.util.Properties;

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.*;
import javax.mail.internet.*;

import javax.activation.FileDataSource;
import javax.activation.DataHandler;



public class sendmail
{
private static final String hostName = "smtp.gmail.com";
private static final int hostPort = 465;
private static final String senderAddress = "[email protected]";
private static final String password = "mypassword";

public void sendEmail(String company, String licence, String remdate, String expdate, String attachments, String supportcontract, String signedcontract, String licenceorigin) throws Exception
{
//Properties
Properties props = new Properties();
props.put("mail.transport.protocol", "smtps");
props.put("mail.smtps.host", hostName);
props.put("mail.smtps.auth", "true");

//Session
Session mailSession = Session.getDefaultInstance(props);
mailSession.setDebug(true);

//Text
MimeBodyPart text = new MimeBodyPart();
text.setText("Company: " + company + "\n Licence: " + licence + "\n Expiration Date: " + expdate + "\n Support Contract: " + supportcontract +
"\n Signed Contract: " + signedcontract + "\n Licence Origin: " + licenceorigin);

//Attachment
FileDataSource fds = new FileDataSource("C:\\temp.png");
MimeBodyPart attachment = new MimeBodyPart();
attachment.setDataHandler(new DataHandler(fds));
attachment.setFileName(fds.getName());

//Create Multipart & Add Parts
Multipart content = new MimeMultipart();
content.addBodyPart(text);
content.addBodyPart(attachment);

//Compile Message
MimeMessage message = new MimeMessage(mailSession);
message.setSubject("Testing Email");
message.setContent(content);
message.addRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));
message.addRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));

//Send Message
Transport transport = mailSession.getTransport();
transport.connect(hostName, hostPort, senderAddress, password);
transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
transport.close();
}

public static void main(String[] args) throws Exception
{
new sendmail().sendEmail("a","b","c","d","e","f","g","h");
}
}

 
Something about .... going for a swim. With this tiny ad ...
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic