I wasn't going to open a question, but I had no solution to this problem!
I have a problem receiving messages from IMAP server.
The error says "Caused by: java.lang.ClassNotFoundException: Didn't find class "java.awt.datatransfer.Transferable" on path...." Here's my code:
enter String test(){
String all="";
try{
class Runner extends AsyncTask<Object, String, String> {
@Override
protected String doInBackground(Object... params) {
Looper.prepare();
String all ="";
try{
Message[] msgs = ReceiveMail("imap.gmail.com","993","USER@gmail.com","PASS"); // After passing this line, error logging says error is in this line!
for(Message m: msgs){
all+=m.getSubject()+"\n"+m.getContent().toString()+"\n\n"; // Error shows here, but popups above
}
return all;
}catch (Exception e){
e.printStackTrace();
}
Looper.loop();
return all;
}
}
Runner r = new Runner();
all = r.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, this).get();
}catch (Exception e){
e.printStackTrace();
}
return all;
}
private Message[] ReceiveMail(String host,String port,String user,String pass){
try{
Properties props = new Properties();
props.setProperty("mail.store.protocol", "imaps");
props.setProperty("mail.imaps.host", host);
props.setProperty("mail.imaps.port", port);
props.setProperty("mail.imaps.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.setProperty("mail.imaps.socketFactory.fallback", "false");
Session imapSession = Session.getInstance(props);
Store store = imapSession.getStore("imaps");
store.connect(host, user, pass);
Folder inbox = store.getFolder("Inbox");
inbox.open(Folder.READ_ONLY);
return inbox.getMessages();
}catch (Exception e){
e.printStackTrace();
//log_all("ReceiveMail function: "+e.getMessage());
}
return null;
}
What is the problem?
Note When I don't use AsyncTask error "Network in main thread" appears.
SOLUTION:
Download these and add them as libraries.
Remove javax.*
from dependencies tab in the module settings
.
That'll solve it.