java 板


LINE

我写了一个小小的寄email的程式然後发现在Eclipse里直接执行的时候一切正常。 但是只要汇出成jar的时候就发现执行会停在某一行addActionListener下。 而且我有加上try&catch在这一行的前後发现执行的时候停在这一行也没有出现 任何的exception,加上其他所有的addActionListener也都没有异常,所以完全 不知道是怎麽一回事@@" 麻烦各位大大帮忙~感恩! 相关程式码如下: ... JButton sendB = new JButton("Send"); ... public void addons_2() { ... //停在这一行 sendB.addActionListener(new SendMail()); ... } //Send E-mails (inner class) private class SendMail implements ActionListener { public void actionPerformed(ActionEvent e) { //A String for setting a SSL Encrypted transmission final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory"; //Various setting for an e-mail trasmission session Properties pts = new Properties(); //Set the address of an SMTP server pts.put("mail.smtp.host", smtpHost); //SMTP server always requires authentication pts.put("mail.smtp.auth", "true"); //Set the port of the SMTP server pts.setProperty("mail.smtp.port", smtpPort); //Set the encoding format of the data transmission as Unicode-8 pts.setProperty("mail.mime.charset", "UTF-8"); //If users decide to use SSL Encrypted transmission if(SSL==true) { //Set SSL pts.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY); } //Add all above properties into a session Session s = Session.getDefaultInstance(pts, null); try { //Set the transmission type of the session as SMTP Transport trans = s.getTransport("smtp"); //Connect to the SMTP server with the address, username //and password trans.connect(smtpHost, username, password); //Cyclically send each e-mail with different attachments for(int loopa=0;loopa<toMail.length;loopa++) { //Create the e-mail MimeMessage mail = new MimeMessage(s); //Create the multipart of the email Multipart mpt = new MimeMultipart(); //Create a body part of the multipart MimeBodyPart mbody = new MimeBodyPart(); //Load the attachment DataSource source = new FileDataSource(attachTF[loopa].getText()); //Set the FROM address of the e-mail mail.setFrom(new InternetAddress(fromMail)); //Set the title of the e-mail mail.setSubject(titleS); //Set the send-date of the e-mail mail.setSentDate(new Date()); //Set the content to a mail body mbody.setText(textS); //Add the mail body of the content as one of //the e-mail's multipart mpt.addBodyPart(mbody); //Create another body part mbody = new MimeBodyPart(); //Set the attachment to this body part mbody.setDataHandler(new DataHandler(source)); //Attach the filename to this body part (Optional?) mbody.setFileName(attachTF[loopa].getText()); //Add the body part of the attachment as another one of the mpt.addBodyPart(mbody); //Set the TO address of the e-mail mail.setRecipients(Message.RecipientType.TO, toMail[loopa]); //Add the multipart into the e-mail mail.setContent(mpt); //Set the REAL(?) address for the transmission InternetAddress[] address = { new InternetAddress(toMail[loopa]) }; //Send the e-mail trans.sendMessage(mail, address); } //Close the connection with the SMTP server trans.close(); //Close the window processWindowEvent(new WindowEvent(new JavaMail(),WindowEvent.WINDOW_CLOSING)); //Show a message of the successful transmission JOptionPane.showMessageDialog(null, "E-mails are sent normally.", "Transmission Complete", JOptionPane.INFORMATION_MESSAGE); } //If unfortunately there's an Exception during the transmission catch(Exception ex) { //Show why there's an exception JOptionPane.showMessageDialog(null, ex + "(If you don't understand this message, report to us)", "Mailing failed", JOptionPane.ERROR_MESSAGE); } } } -- 你来到了天母棒球场,这里正在进行一场棒球比赛。场上球员似乎火气很大呢! (上火) 林岳平 (Lin Yue-Ping) (闪光) 冯胜贤 (Feng Sheng-Xien) [生命:86 精神:1079 体力:48]: throw Feng ball 你把一颗球丢到 冯胜贤 (Feng Sheng-xien)身上了! 你被传送到了法庭里!你一脸的茫然… --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 123.204.180.200 ※ 编辑: KeeperOf7Key 来自: 123.204.180.200 (07/16 11:25)
1F:推 PsMonkey:SendMail 的细节咧.... @_@ 07/16 12:33
补落落长SendMail的细节…麻烦了<(_ _)>
2F:→ Schelfaniel:会不会是缺函式?? 07/16 13:40
另外补充就是用过winRAR开过包起来的jar有确定inner class的编译档也有包进去… ※ 编辑: KeeperOf7Key 来自: 123.204.180.214 (07/16 16:26) ※ 编辑: KeeperOf7Key 来自: 123.204.180.214 (07/16 16:30)
3F:推 PsMonkey:理论上应该没有缺 3rd class,有 exception 也会有反应.. 07/16 17:33
4F:推 PsMonkey:只一行行卡 out.print(),先抓死在那一行了 (好弱 Orz) 07/16 17:34
5F:→ PsMonkey:等等,那个 javax.net.ssl.SSLSocketFactory 真的有吗? 07/16 17:36
不过我抓是跑到addons_2里那一行addActionListener就停住了(後面还有validate();) 照理来说应该也还没用到SendMail里的任何一条码说(还没有按sendB呀…)…orz 另外"javax.net.ssl.SSLSocketFactory"我也不知道~还没测到这边XDrz ※ 编辑: KeeperOf7Key 来自: 123.204.180.214 (07/16 20:24)
6F:→ TonyQ:我视觉得你应该要先检查sendMail的建构子.. 07/17 16:57
7F:→ KeeperOf7Key:但是我SendMail没有写建构子呀… 07/19 00:35







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:Gossiping站内搜寻

TOP