java.lang.NoClassDefFoundError:android中的javax.activation.DataHandler

时间:2023-01-19 21:50:12

I am making a email sending application in android phone. For that I included two jar file activation. jar and mail.jar. But when I run this application and try to send the mail, I got following error on LogCat.

我在android手机中发送电子邮件发送应用程序。为此,我包括两个jar文件激活。 jar和mail.jar。但是,当我运行此应用程序并尝试发送邮件时,我在LogCat上遇到以下错误。

java.lang.NoClassDefFoundError: javax.activation.DataHandler 

I am new to android. so I am not able to figure out this issue. please Help me. Thanks

我是android的新手。所以我无法弄清楚这个问题。请帮我。谢谢

2 个解决方案

#1


61  

There is an Android-friendly port of javamail which you should be using. There are three libraries that you need to include in your app: mail.jar, activation.jar, and additionnal.jar(sic). It looks like you are missing something that the activation library depends on, and this could be because you are not using the Android port of this library.

你应该使用一个Android友好的javamail端口。您需要在应用中包含三个库:mail.jar,activation.jar和additionnal.jar(sic)。看起来您遗漏了激活库所依赖的内容,这可能是因为您没有使用此库的Android端口。

I have used the Android-friendly version of javamail successfully in a project, and it works really well.

我在一个项目中成功使用了Android友好版本的javamail,它运行得非常好。

#2


5  

The JavaMail API Reference Implementation version 1.5.5 and later have built in support for Android and include support for OAuth2.

JavaMail API参考实现版本1.5.5及更高版本内置了对Android的支持,并包含对OAuth2的支持。

Per the documentation:

根据文件:

Android does not provide a Java Compatible runtime and so can't run the standard JavaMail distribution. Instead, a special version of JavaMail is available for Android. This special version of JavaMail depends on a special version of the JavaBeans Activation Framework.

Android不提供Java Compatible运行时,因此无法运行标准JavaMail分发。相反,Android的特殊版本的JavaMail可用。这个特殊版本的JavaMail依赖于特殊版本的JavaBeans Activation Framework。

You can try out this version by adding the following to your build.gradle file for your Android application:

您可以通过将以下内容添加到Android应用程序的build.gradle文件中来试用此版本:

 android {
     packagingOptions {
         pickFirst 'META-INF/LICENSE.txt' // picks the JavaMail license file
     }
 }

 repositories { 
     jcenter()
     maven {
         url "https://maven.java.net/content/groups/public/"
     }
 }

 dependencies {
     compile 'com.sun.mail:android-mail:1.5.5'
     compile 'com.sun.mail:android-activation:1.5.5'
 }

Starting with JavaMail 1.6.0:

从JavaMail 1.6.0开始:

JavaMail for Android requires at least Android API level 19, which corresponds to Android KitKat, currently the oldest supported version of Android.

JavaMail for Android至少需要Android API级别19,它对应于Android KitKat,这是目前支持最新的Android版本。

#1


61  

There is an Android-friendly port of javamail which you should be using. There are three libraries that you need to include in your app: mail.jar, activation.jar, and additionnal.jar(sic). It looks like you are missing something that the activation library depends on, and this could be because you are not using the Android port of this library.

你应该使用一个Android友好的javamail端口。您需要在应用中包含三个库:mail.jar,activation.jar和additionnal.jar(sic)。看起来您遗漏了激活库所依赖的内容,这可能是因为您没有使用此库的Android端口。

I have used the Android-friendly version of javamail successfully in a project, and it works really well.

我在一个项目中成功使用了Android友好版本的javamail,它运行得非常好。

#2


5  

The JavaMail API Reference Implementation version 1.5.5 and later have built in support for Android and include support for OAuth2.

JavaMail API参考实现版本1.5.5及更高版本内置了对Android的支持,并包含对OAuth2的支持。

Per the documentation:

根据文件:

Android does not provide a Java Compatible runtime and so can't run the standard JavaMail distribution. Instead, a special version of JavaMail is available for Android. This special version of JavaMail depends on a special version of the JavaBeans Activation Framework.

Android不提供Java Compatible运行时,因此无法运行标准JavaMail分发。相反,Android的特殊版本的JavaMail可用。这个特殊版本的JavaMail依赖于特殊版本的JavaBeans Activation Framework。

You can try out this version by adding the following to your build.gradle file for your Android application:

您可以通过将以下内容添加到Android应用程序的build.gradle文件中来试用此版本:

 android {
     packagingOptions {
         pickFirst 'META-INF/LICENSE.txt' // picks the JavaMail license file
     }
 }

 repositories { 
     jcenter()
     maven {
         url "https://maven.java.net/content/groups/public/"
     }
 }

 dependencies {
     compile 'com.sun.mail:android-mail:1.5.5'
     compile 'com.sun.mail:android-activation:1.5.5'
 }

Starting with JavaMail 1.6.0:

从JavaMail 1.6.0开始:

JavaMail for Android requires at least Android API level 19, which corresponds to Android KitKat, currently the oldest supported version of Android.

JavaMail for Android至少需要Android API级别19,它对应于Android KitKat,这是目前支持最新的Android版本。