title: Java.lang.NoClassDefFoundError - JavaMail
body: <p>I have a thread inside my main activity, which will create an object of the class <code>SendMail</code></p>
  
  <pre><code>package Logic;
  
  import java.util.Date;
  import java.util.Properties;
  
  import javax.activation.DataHandler;
  import javax.activation.FileDataSource;
  import javax.mail.Message;
  import javax.mail.MessagingException;
  import javax.mail.Multipart;
  import javax.mail.Session;
  import javax.mail.Transport;
  import javax.mail.internet.AddressException;
  import javax.mail.internet.InternetAddress;
  import javax.mail.internet.MimeBodyPart;
  import javax.mail.internet.MimeMessage;
  import javax.mail.internet.MimeMultipart;
  
  import android.util.Log;
  
  public class SendMail {
  
  String from;
  String to;
  String subject;
  String bodyText;
  String fileName;
  
  public SendMail(String to, String fileName, String PCN) {
  
      this.to = to;
      this.fileName = fileName;
      this.from = "Hello@gmail.com";
      this.bodyText = "FILE";
      this.subject = PCN;
  }
  
  public void sendMailWithAttatchment() {
  
      Properties properties = new Properties();
      properties.put("mail.smtp.host", "IP_ADDRESS");
      properties.put("mail.smtp.port", "25");
      Session session = Session.getDefaultInstance(properties, null);
  
      MimeMessage message = new MimeMessage(session);
  
      try {
  
          message.setFrom(new InternetAddress(from));
  
          message.setRecipient(Message.RecipientType.TO, new InternetAddress(
                  to));
          message.setSubject(subject);
          message.setSentDate(new Date());
  
          MimeBodyPart messagePart = new MimeBodyPart();
          messagePart.setText(bodyText);
  
          MimeBodyPart attachmentPart = new MimeBodyPart();
  
          FileDataSource fileDataSource = new FileDataSource(fileName) {
              @Override
              public String getContentType() {
                  return "application/octet-stream";
  
              }
          };
  
          attachmentPart.setDataHandler(new DataHandler(fileDataSource));
          attachmentPart.setFileName(fileDataSource.getName());
  
          Multipart multipart = new MimeMultipart();
          multipart.addBodyPart(messagePart);
          multipart.addBodyPart(attachmentPart);
          message.setContent(multipart);
          Transport.send(message);
      } catch (AddressException e) {
          Log.e("ADDRESS_EXCEPTION: ", e.getMessage());
      } catch (MessagingException e) {
          Log.e("MESSAGING_EXCEPTION: ", e.getMessage());
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>But the compiler throws an Exception saying: <code>Java.lang.NoClassDefFoundError. javax.activation.Datahandler</code></p>
  
  <p>I've read this thread: <a href="https://stackoverflow.com/questions/2247998/noclassdeffounderror-eclipse-and-android">NoClassDefFoundError - Eclipse and Android</a> and the <code>.jar files</code> <code>javamail.jar</code> and <code>javax.activation.jar</code> is located under my <code>libs</code> folder, but this throws an exception even if I clean the project. </p>
  
  <p>Any ideas? </p>
  
  <p>These are the exception which is thrown:</p>
  
  <pre><code>08-07 10:19:49.870: E/AndroidRuntime(17736): java.lang.NoClassDefFoundError: javax.activation.DataHandler
  08-07 10:19:49.870: E/AndroidRuntime(17736):    at javax.mail.internet.MimeBodyPart.setContent(MimeBodyPart.java:647)
  08-07 10:19:49.870: E/AndroidRuntime(17736):    at javax.mail.internet.MimeBodyPart.setText(MimeBodyPart.java:892)
  08-07 10:19:49.870: E/AndroidRuntime(17736):    at javax.mail.internet.MimeBodyPart.setText(MimeBodyPart.java:680)
  08-07 10:19:49.870: E/AndroidRuntime(17736):    at javax.mail.internet.MimeBodyPart.setText(MimeBodyPart.java:668)
  08-07 10:19:49.870: E/AndroidRuntime(17736):    at sendMailWithAttatchment(SendMail.java:56)
  08-07 10:19:49.870: E/AndroidRuntime(17736):    at sendMailWithAttatchment(SendMail.java:56)
  08-07 10:19:49.870: E/AndroidRuntime(17736):    at CreateNistFile(MyActivity.java:530)
  </code></pre>