作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 IntelliJ IDEA 中创建了一个空的 Android 项目,并将以下行添加到 app/build.gradle
:
dependencies {
...
compile 'javax.mail:javax.mail-api:1.6.2'
...
}
现在我可以import javax.mail.internet.MimeBodyPart;
和 javax.mail
中的其他类:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new MimeBodyPart();
}
应用程序构建成功。但是,如果我运行它,我会得到 FATAL EXCEPTION
:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/sun/mail/util/PropUtil;
at javax.mail.internet.MimeBodyPart.<clinit>(MimeBodyPart.java:91)
at com.example.myapplication.MainActivity.onCreate(MainActivity.java:15)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.sun.mail.util.PropUtil" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.example.myapplication-gtunpTdStbiuDO78f_fC_g==/base.apk", zip file "/data/app/com.example.myapplication-gtunpTdStbiuDO78f_fC_g==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.myapplication-gtunpTdStbiuDO78f_fC_g==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.myapplication-gtunpTdStbiuDO78f_fC_g==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.myapplication-gtunpTdStbiuDO78f_fC_g==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.myapplication-gtunpTdStbiuDO78f_fC_g==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.myapplication-gtunpTdStbiuDO78f_fC_g==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.myapplication-gtunpTdStbiuDO78f_fC_g==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.myapplication-gtunpTdStbiuDO78f_fC_g==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.myapplication-gtunpTdStbiuDO78f_fC_g==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.myapplication-gtunpTdStbiuDO78f_fC_g==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.myapplication-gtunpTdStbiuDO78f_fC_g==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.myapplication-gtunpTdStbiuDO78f_fC_g==/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at javax.mail.internet.MimeBodyPart.<clinit>(MimeBodyPart.java:91)
at com.example.myapplication.MainActivity.onCreate(MainActivity.java:15)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
最佳答案
javax.mail:javax.mail-api:1.6.2
是 Java SE 的实现,不适用于 Android。尝试使用另一个库:
compile 'com.sun.mail:android-mail:1.6.2'
关于android - java.lang.NoClassDefFoundError : Failed resolution of: Lcom/sun/mail/util/PropUtil; when trying to use javax. 邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53784104/
我在 IntelliJ IDEA 中创建了一个空的 Android 项目,并将以下行添加到 app/build.gradle: dependencies { ... compile 'ja
我是一名优秀的程序员,十分优秀!