I'm building an app to log into Facebook, Twitter, Hotmail and Gmail accounts and have a combined inbox to view the feeds/messages. Everything was working fine until the 24 of Jan 2013, but after than the app crashes when login into the Gmail account. If login details are wrong app does not crash, if login details are right the app show the Toast "login successful" and than when moving into my combined inbox it crashes. 3 days ago' I run it again with no problems (didn't have any changes made to the code) than I was unable to login into Gmail again. my code for the Gmail login is the following:
// Execute Gmail Login
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
and here is the logcat relative to this problem:
02-09 11:17:28.187: I/Choreographer(759): Skipped 39 frames! The application may be doing too much work on its main thread.
02-09 11:17:28.436: E/AndroidRuntime(759): FATAL EXCEPTION: AsyncTask #1
02-09 11:17:28.436: E/AndroidRuntime(759): java.lang.RuntimeException: An error occured while executing doInBackground()
02-09 11:17:28.436: E/AndroidRuntime(759): at android.os.AsyncTask$3.done(AsyncTask.java:299)
02-09 11:17:28.436: E/AndroidRuntime(759): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
02-09 11:17:28.436: E/AndroidRuntime(759): at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
02-09 11:17:28.436: E/AndroidRuntime(759): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
02-09 11:17:28.436: E/AndroidRuntime(759): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
02-09 11:17:28.436: E/AndroidRuntime(759): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
02-09 11:17:28.436: E/AndroidRuntime(759): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
02-09 11:17:28.436: E/AndroidRuntime(759): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
02-09 11:17:28.436: E/AndroidRuntime(759): at java.lang.Thread.run(Thread.java:856)
02-09 11:17:28.436: E/AndroidRuntime(759): Caused by: java.lang.IndexOutOfBoundsException
02-09 11:17:28.436: E/AndroidRuntime(759): at com.sun.mail.imap.IMAPFolder.checkRange(IMAPFolder.java:429)
02-09 11:17:28.436: E/AndroidRuntime(759): at com.sun.mail.imap.IMAPFolder.getMessage(IMAPFolder.java:1365)
02-09 11:17:28.436: E/AndroidRuntime(759): at javax.mail.Folder.getMessages(Folder.java:879)
02-09 11:17:28.436: E/AndroidRuntime(759): at com.fyp.Gmail.getMails(Gmail.java:161)
02-09 11:17:28.436: E/AndroidRuntime(759): at com.fyp.InboxActivity$RecieveGmail.doInBackground(InboxActivity.java:510)
02-09 11:17:28.436: E/AndroidRuntime(759): at com.fyp.InboxActivity$RecieveGmail.doInBackground(InboxActivity.java:1)
02-09 11:17:28.436: E/AndroidRuntime(759): at android.os.AsyncTask$2.call(AsyncTask.java:287)
02-09 11:17:28.436: E/AndroidRuntime(759): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
02-09 11:17:28.436: E/AndroidRuntime(759): ... 5 more
02-09 11:17:28.956: I/Choreographer(759): Skipped 56 frames! The application may be doing too much work on its main thread.
02-09 11:17:29.446: I/Choreographer(759): Skipped 125 frames! The application may be doing too much work on its main thread.
02-09 11:17:29.606: I/Choreographer(759): Skipped 34 frames! The application may be doing too much work on its main thread.
I don't understand why it worked for nearly 2 months and than stopped working without importing any changes to the code
If anybody has any idea about this problem I'll really appreciate it
the Gmail.getMails method is the following:
//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;
}
}