问题描述
我不会打开一个问题,但是我没有解决这个问题的方法!
我从IMAP服务器接收消息时遇到问题。
错误说引起:java.lang.ClassNotFoundException:路径上没有找到类java.awt.datatransfer.Transferable....这是我的代码:
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","[email protected]","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;
}
有什么问题?
注意当我不使用AsyncTask错误时出现主线程中的网络。
What is the problem?
Note When I don't use AsyncTask error "Network in main thread" appears.
解决方案:
下载并将其添加为库。
从模块设置
中的依赖项选项卡中删除 javax。*
。
那将是解决它。
SOLUTION:
Download these and add them as libraries.
Remove javax.*
from dependencies tab in the module settings
.
That'll solve it.
推荐答案
既然找不到某个类可能你错过了一个外部的jar?
Since it doesn't find some class maybe you are missing an external jar?
编辑
您可以使用JavaMail API处理电子邮件任务。 JavaMail API在JavaEE包中可用,其jar可供下载。遗憾的是,它不能直接在Android应用程序中使用,因为它使用了在Android中完全不兼容的AWT组件。 (这就是为什么会出现此错误)
You can use JavaMail API to handle your email tasks. JavaMail API is available in JavaEE package and its jar is available for download. Sadly it cannot be used directly in an Android application since it uses AWT components which are completely incompatible in Android. (Thats why you get this error)
您可以在以下位置找到JavaMail的Android端口:
You can find the Android port for JavaMail at the following location: http://code.google.com/p/javamail-android/
将jar添加到您的应用程序并使用SMTP方法
Add the jars to your application and use the SMTP method
这篇关于JavaMail:Java.awt.datatransfer.Transferable不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!