0

I'm trying to write an app that will send an automated email from a button push in an Android application.

I realize this question has been asked multiple times, but I still have not found a final solution for it for my case.

The code example I followed came from here:

http://macmaker.blogspot.com/2012/04/send-emails-in-background-in.html

The GMailSender class is exactly the same. So is the MainActivity class except I use my own email to test that it is sending properly.

The two main questions I have looked at are the following:

Android sending emails java.lang.NoClassDefFoundError: javax.activation.DataHandler

java.lang.NoClassDefFoundError: javax.activation.DataHandler in android

I have all three files (activation.jar, additionnal.jar, mail.jar) put into my project as Modules. This was done by following the example in this YouTube video:

https://www.youtube.com/watch?v=dpuJPoXkFG4

However, I still keep getting this error:

08-25 14:10:24.968  29531-29531/com.example.mailapp E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.mailapp, PID: 29531
java.lang.NoClassDefFoundError: javax.activation.DataHandler
        at com.example.mailapp.GMail.send(GMail.java:103)
        at com.example.mailapp.MainActivity$1.onClick(MainActivity.java:33)
        at android.view.View.performClick(View.java:4780)
        at android.view.View$PerformClick.run(View.java:19866)
        at android.os.Handler.handleCallback(Handler.java:739)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:135)
        at android.app.ActivityThread.main(ActivityThread.java:5254)
        at java.lang.reflect.Method.invoke(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:372)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

I'm not sure if the steps in the YouTube video I followed is the reason why it's not working properly or if there is something wrong with the code in general.

If you have any suggestions please help.

EDIT: I also have attempted to place all of the .jar files in the libs folder and make sure that they are in the build.gradle file under dependencies as follows:

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.0'
compile project(':activation')
compile project(':additionnal')
compile project(':mail')
compile files('libs/activation.jar')
compile files('libs/additionnal.jar')
compile files('libs/mail.jar')
}

I did this by looking at this question:

Android Studio: Add jar as library?

But the error still persists.

EDIT 2: When the .jar files are in my libs folder (and in the modules) I can find the DataHandler class. However, when I click on it to view it, a message at the top of the screen appears that says "Decompiled .class file, bytecode version: 48.0 (Java 1.4)"

Not sure if that is useful to anyone on this site. Also, the file is locked as in I can't edit it which is what I would expect.

Community
  • 1
  • 1
Beren
  • 131
  • 1
  • 1
  • 13

1 Answers1

2

For whatever reason, the activation.jar file that I downloaded didn't work the first time. I kept finding that it was Decompiled .class file, bytecode version: 48.0 (Java 1.4)

I then deleted all of the files I got from the following link:

https://code.google.com/p/javamail-android/downloads/list

And then redownloaded all of those files again. Then I went through the whole process of adding them back as libraries in my app.

Now everything works just fine and when looking at the DataHandler class from the activation.jar it says "Decompiled .class file, bytecode version: 49.0 (Java 5.0)"

I still do not know why when I first downloaded it, it didn't work, but it works fine now.

Beren
  • 131
  • 1
  • 1
  • 13