Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java android应用程序:Gmail导致应用程序在登录后崩溃_Java_Android - Fatal编程技术网

Java android应用程序:Gmail导致应用程序在登录后崩溃

Java android应用程序:Gmail导致应用程序在登录后崩溃,java,android,Java,Android,我正在开发一个应用程序,可以登录Facebook、Twitter、Hotmail和Gmail帐户,并有一个组合收件箱来查看提要/消息。在2013年1月24日之前,一切正常,但之后,当登录到Gmail帐户时,应用程序崩溃。如果登录详细信息错误,则应用程序不会崩溃;如果登录详细信息正确,则应用程序将显示“登录成功”,然后在移动到我的组合收件箱时崩溃。3天前,我再次运行它,没有任何问题(没有对代码进行任何更改),但我无法再次登录Gmail。 我的Gmail登录代码如下: //Get mails fr

我正在开发一个应用程序,可以登录Facebook、Twitter、Hotmail和Gmail帐户,并有一个组合收件箱来查看提要/消息。在2013年1月24日之前,一切正常,但之后,当登录到Gmail帐户时,应用程序崩溃。如果登录详细信息错误,则应用程序不会崩溃;如果登录详细信息正确,则应用程序将显示“登录成功”,然后在移动到我的组合收件箱时崩溃。3天前,我再次运行它,没有任何问题(没有对代码进行任何更改),但我无法再次登录Gmail。 我的Gmail登录代码如下:

 //Get mails from gmail.
public static Message[] getMails(final String username, final String password) {
    Properties props = System.getProperties();
    // props.setProperty("mail.store.protocol", "imaps");
    // props.put("mail.smtp.starttls.enable", "true");

    props.put("mail.imap.host", "imap.gmail.com");
    props.put("mail.imap.user", username);
    // User SSL
    props.put("mail.imap.socketFactory", 993);
    props.put("mail.imap.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    props.put("mail.imap.port", 993);
    Authenticator auth = new Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(username, password);
        }

    };

    Session sessioned = Session.getDefaultInstance(props, auth);

    Store store;
    try {
        store = sessioned.getStore("imaps");
        store.connect("smtp.gmail.com", username, password);

        Folder inbox = store.getFolder("inbox");
        inbox.open(Folder.READ_WRITE);
        // FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
        // Message[] unReadMessages = inbox.search(ft);
        int total=inbox.getMessageCount();
        Message[] unReadMessages = reverseMsgs(inbox.getMessages(total-15,total)); 
        //= inbox.getMessages(total,total-15);
        return unReadMessages;
    } catch (NoSuchProviderException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    } catch (MessagingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    }

}
//执行Gmail登录

public class GmailLogin extends AsyncTask<String, Integer, Boolean> {
    String username;
    String password;

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        Toast.makeText(getApplicationContext(), R.string.Executing_Gmail_login,
                //Toast.makeText(getApplicationContext(), "Executing Gmail login..",
                Toast.LENGTH_LONG).show();
        super.onPreExecute();
    }

    @Override
    protected Boolean doInBackground(final String... params) {
        username = params[0];
        password = params[1];
        return Gmail.doGmailLogin(params[0], params[1]);
    }

    @Override
    protected void onPostExecute(Boolean result) {
        // TODO Auto-generated method stub
        if (result) {
            SharedPreferences gmailPreference = getSharedPreferences(
                    Const.GMAIL_PREF_NAME, 0);
            Utility.saveGmailPrefrences(gmailPreference, username, password);
            Toast.makeText(getApplicationContext(), R.string.Gmail_Login_success,
                    //Toast.makeText(getApplicationContext(), "Gmail Login succesful",
                    Toast.LENGTH_LONG).show();
            gotoInbox();
        } else {

            Toast.makeText(getApplicationContext(),
                    R.string.Invalid_login_try_again, Toast.LENGTH_LONG)
                    //"Invalid login. Please try again", Toast.LENGTH_LONG)
                    .show();

        }
        super.onPostExecute(result);
    }

}//end of GmailLogin class
我不明白为什么它工作了将近2个月,然后在没有导入任何代码更改的情况下停止工作

如果有人知道这个问题,我会非常感激的

Gmail.getMail方法如下所示:

 //Get mails from gmail.
public static Message[] getMails(final String username, final String password) {
    Properties props = System.getProperties();
    // props.setProperty("mail.store.protocol", "imaps");
    // props.put("mail.smtp.starttls.enable", "true");

    props.put("mail.imap.host", "imap.gmail.com");
    props.put("mail.imap.user", username);
    // User SSL
    props.put("mail.imap.socketFactory", 993);
    props.put("mail.imap.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    props.put("mail.imap.port", 993);
    Authenticator auth = new Authenticator() {
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(username, password);
        }

    };

    Session sessioned = Session.getDefaultInstance(props, auth);

    Store store;
    try {
        store = sessioned.getStore("imaps");
        store.connect("smtp.gmail.com", username, password);

        Folder inbox = store.getFolder("inbox");
        inbox.open(Folder.READ_WRITE);
        // FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
        // Message[] unReadMessages = inbox.search(ft);
        int total=inbox.getMessageCount();
        Message[] unReadMessages = reverseMsgs(inbox.getMessages(total-15,total)); 
        //= inbox.getMessages(total,total-15);
        return unReadMessages;
    } catch (NoSuchProviderException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    } catch (MessagingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    }

}

发布Gmail.getMail(Gmail.java:161)方法..我编辑了问题并添加了您询问的方法。发布第161行Gmail上写的内容。第161行如下:Message[]unReadMessages=reverseMsgs(inbox.getMessages(total-15,total));