使用JavaMail在Android应用程序中接收电子邮件时出错

时间:2014-10-19 17:22:20

标签: java android eclipse javamail

我正在尝试使用以下代码在我的Android应用程序中使用JavaMail收发电子邮件:

private String[] ReadMailbox(String MailboxName) throws IOException {
    Properties props = new Properties();
    props.setProperty("mail.store.protocol", "imaps");
    props.setProperty("mail.imaps.host", "imap.gmail.com");
    props.setProperty("mail.imaps.port", "993");
    List<String> FromAddressArrList = new ArrayList<String>();

    try {
        Session session = Session.getInstance(props, null);
        Store store = session.getStore();
        store.connect("imap.gmail.com", "myusername", "mypassword");
        ActiveMailbox = store.getFolder(MailboxName);
        ActiveMailbox.open(Folder.READ_ONLY);
        Message[] messages = ActiveMailbox.getMessages();
        //System.out.println("Number of mails = " + messages.length);
        for (int i = 0; i < messages.length; i++) {
            Message message = messages[i];
            Address[] from = message.getFrom();
            FromAddressArrList.add(from[0].toString());
        }
        //ActiveMailbox.close(true);
        store.close();
    } catch (NoSuchProviderException e) {
        e.printStackTrace();
    } catch (MessagingException e) {
        e.printStackTrace();
    }
    String[] FromAddressArr = new String[FromAddressArrList.size()];
    FromAddressArrList.toArray(FromAddressArr);
    return FromAddressArr;
}

但是当我运行应用程序时出现此错误:

10-19 16:48:00.120: E/AndroidRuntime(1044): FATAL EXCEPTION: main 10-19 16:48:00.120: E/AndroidRuntime(1044): java.lang.VerifyError: com/mailcry/android/MainActivity 10-19 16:48:00.120: E/AndroidRuntime(1044): at java.lang.Class.newInstanceImpl(Native Method) 10-19 16:48:00.120: E/AndroidRuntime(1044): at java.lang.Class.newInstance(Class.java:1319) 10-19 16:48:00.120: E/AndroidRuntime(1044): at android.app.Instrumentation.newActivity(Instrumentation.java:1053) 10-19 16:48:00.120: E/AndroidRuntime(1044): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974) 10-19 16:48:00.120: E/AndroidRuntime(1044): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) 10-19 16:48:00.120: E/AndroidRuntime(1044): at android.app.ActivityThread.access$600(ActivityThread.java:130) 10-19 16:48:00.120: E/AndroidRuntime(1044): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) 10-19 16:48:00.120: E/AndroidRuntime(1044): at android.os.Handler.dispatchMessage(Handler.java:99) 10-19 16:48:00.120: E/AndroidRuntime(1044): at android.os.Looper.loop(Looper.java:137) 10-19 16:48:00.120: E/AndroidRuntime(1044): at android.app.ActivityThread.main(ActivityThread.java:4745) 10-19 16:48:00.120: E/AndroidRuntime(1044): at java.lang.reflect.Method.invokeNative(Native Method) 10-19 16:48:00.120: E/AndroidRuntime(1044): at java.lang.reflect.Method.invoke(Method.java:511) 10-19 16:48:00.120: E/AndroidRuntime(1044): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 10-19 16:48:00.120: E/AndroidRuntime(1044): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 10-19 16:48:00.120: E/AndroidRuntime(1044): at dalvik.system.NativeStart.main(Native Method)

我没有调试Android或Java应用程序的经验,我需要你的帮助。

提前谢谢!

1 个答案:

答案 0 :(得分:0)

我没有将JavaMail添加到我的libs Android应用程序文件夹中。一旦我做了,一切都运转正常。