2017-04-17 85 views
0

나는 안드로이드 OS 용 이메일 전송 응용 프로그램을 만들고 있습니다. 내 libs 폴더에 activation.jar, additional.jar 및 mail.jar 세 개의 jar가 있습니다. 또한이 세 개의 병이 프로젝트의 빌드 경로에 "참조 된 라이브러리"로 포함되어 있습니다. 이 응용 프로그램을 실행하고 메일을 보내려고하면 LogCat에서 다음 오류가 발생합니다.치명적인 예외 : java.lang.NoClassDefFoundError : javax.activation.DataHandler

FATAL EXCEPTION: java.lang.NoClassDefFoundError: javax.activation.DataHandler

많은 다른 사람들이 동일한 NoClassDefFoundError 오류를 가지고 있기 때문에 나는 완전히 혼란 스럽습니다. https://stackoverflow.com/a/34419/3576562 참고 : 나는 라이브러리 내 클래스 빌드 경로에 포함 된 필요한 항아리를 가지고 있기 때문에, 나는 링크에 설명 된대로 런타임 오류가 될 수 있다고 생각 http://www.chengxuyuans.com/qa/android/85326.html

Activity.java : :이 안드로이드 이메일 튜토리얼을 따라

Button dialogButton1 = (Button) dialog.findViewById(R.id.SendButton); 
       dialogButton1.setOnClickListener(new OnClickListener() { 
        @Override 
        public void onClick(View v) { 
         //Toast.makeText(getApplicationContext(), "Forgot-Password-Request button", Toast.LENGTH_LONG).show(); 
         final EditText email = (EditText) dialog.findViewById(R.id.EditEmail); 
         if(email.getText() != null && email.getText().toString().trim().length() > 0){//check for email written. 
          Runnable run = new Runnable() { 
           public void run() { 
            SendPasswordRequestEmail(email.getText().toString()); 
            dialog.dismiss(); 
           } 
          }; 
          (new Thread(run)).start(); 

         } 
        } 
       }); 

public void SendPasswordRequestEmail(String emailAddress){ 
     try{ 
      GMailSender sender = new GMailSender("[email protected]", "email password"); 
      sender.sendMail("This is Subject", 
        "This is Body", 
        "[email protected]", 
        "[email protected]"); 
     }catch (Exception ex) { 
      Log.e("MailChimp", "SendEmail Method-Exception forgot password email: " + ex.getMessage()); 
      showResult("SendEmail Method-Exception forgot password email: "+ex.getMessage(), "Error"); 
      ex.printStackTrace(); 
     } 
    } 

GMailSender.java :

package com.example.proactiveregistrationapplication; 
import javax.activation.DataHandler; 
import javax.activation.DataSource; 
import javax.mail.Message; 
import javax.mail.PasswordAuthentication; 
import javax.mail.Session; 
import javax.mail.Transport; 
import javax.mail.internet.InternetAddress; 
import javax.mail.internet.MimeMessage; 
import java.io.ByteArrayInputStream; 
import java.io.IOException; 
import java.io.InputStream; 
import java.io.OutputStream; 
import java.security.Security; 
import java.util.Properties; 

public class GMailSender extends javax.mail.Authenticator { 
    private String mailhost = "smtp.gmail.com"; 
    private String user; 
    private String password; 
    private Session session; 

    static { 
     Security.addProvider(new com.example.proactiveregistrationapplication.JSSEProvider()); 
    } 

    public GMailSender(String user, String password) { 
     this.user = user; 
     this.password = password; 

     Properties props = new Properties(); 
     props.setProperty("mail.transport.protocol", "smtp"); 
     props.setProperty("mail.host", mailhost); 
     props.put("mail.smtp.auth", "true"); 
     props.put("mail.smtp.port", "465"); 
     props.put("mail.smtp.socketFactory.port", "465"); 
     props.put("mail.smtp.socketFactory.class", 
       "javax.net.ssl.SSLSocketFactory"); 
     props.put("mail.smtp.socketFactory.fallback", "false"); 
     props.setProperty("mail.smtp.quitwait", "false"); 

     session = Session.getDefaultInstance(props, this); 
    } 

    protected PasswordAuthentication getPasswordAuthentication() { 
     return new PasswordAuthentication(user, password); 
    } 

    public synchronized void sendMail(String subject, String body, String sender, String recipients) throws Exception { 
     try{ 
     MimeMessage message = new MimeMessage(session); 
     DataHandler handler = new DataHandler(new ByteArrayDataSource(body.getBytes(), "text/plain")); 
     message.setSender(new InternetAddress(sender)); 
     message.setSubject(subject); 
     message.setDataHandler(handler); 
     if (recipients.indexOf(',') > 0) 
      message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipients)); 
     else 
      message.setRecipient(Message.RecipientType.TO, new InternetAddress(recipients)); 
     Transport.send(message); 
     }catch(Exception e){ 

     } 
    } 

    public class ByteArrayDataSource implements DataSource { 
     private byte[] data; 
     private String type; 

     public ByteArrayDataSource(byte[] data, String type) { 
      super(); 
      this.data = data; 
      this.type = type; 
     } 

     public ByteArrayDataSource(byte[] data) { 
      super(); 
      this.data = data; 
     } 

     public void setType(String type) { 
      this.type = type; 
     } 

     public String getContentType() { 
      if (type == null) 
       return "application/octet-stream"; 
      else 
       return type; 
     } 

     public InputStream getInputStream() throws IOException { 
      return new ByteArrayInputStream(data); 
     } 

     public String getName() { 
      return "ByteArrayDataSource"; 
     } 

     public OutputStream getOutputStream() throws IOException { 
      throw new IOException("Not Supported"); 
     } 
    } 
} 

JSSEProvider.java :

package com.example.proactiveregistrationapplication; 

import java.security.AccessController; 
import java.security.Provider; 

public final class JSSEProvider extends Provider { 

    public JSSEProvider() { 
     super("HarmonyJSSE", 1.0, "Harmony JSSE Provider"); 
     AccessController.doPrivileged(new java.security.PrivilegedAction<Void>() { 
      public Void run() { 
       put("SSLContext.TLS", 
         "org.apache.harmony.xnet.provider.jsse.SSLContextImpl"); 
       put("Alg.Alias.SSLContext.TLSv1", "TLS"); 
       put("KeyManagerFactory.X509", 
         "org.apache.harmony.xnet.provider.jsse.KeyManagerFactoryImpl"); 
       put("TrustManagerFactory.X509", 
         "org.apache.harmony.xnet.provider.jsse.TrustManagerFactoryImpl"); 
       return null; 
      } 
     }); 
    } 
} 

로그 캣 오류 :

04-17 16:15:04.395: I/art(26895): Rejecting re-init on previously-failed class java.lang.Class<javax.activation.DataHandler> 
04-17 16:15:04.395: I/art(26895): Rejecting re-init on previously-failed class java.lang.Class<javax.activation.DataHandler> 
04-17 16:15:04.415: W/(26895): Unable to open '/system/framework/com.qti.location.sdk.jar': No such file or directory 
04-17 16:15:04.415: W/art(26895): Failed to open zip archive '/system/framework/com.qti.location.sdk.jar': I/O Error 
04-17 16:15:04.435: W/(26895): Unable to open '/system/framework/com.qti.location.sdk.jar': No such file or directory 
04-17 16:15:04.435: W/art(26895): Failed to open zip archive '/system/framework/com.qti.location.sdk.jar': I/O Error 
04-17 16:15:04.435: W/(26895): Unable to open '/system/framework/com.qti.location.sdk.jar': No such file or directory 
04-17 16:15:04.435: W/art(26895): Failed to open zip archive '/system/framework/com.qti.location.sdk.jar': I/O Error 
04-17 16:15:04.445: W/(26895): Unable to open '/system/framework/com.qti.location.sdk.jar': No such file or directory 
04-17 16:15:04.445: W/art(26895): Failed to open zip archive '/system/framework/com.qti.location.sdk.jar': I/O Error 
04-17 16:15:04.455: W/(26895): Unable to open '/system/framework/com.qti.location.sdk.jar': No such file or directory 
04-17 16:15:04.455: W/art(26895): Failed to open zip archive '/system/framework/com.qti.location.sdk.jar': I/O Error 
04-17 16:15:04.455: W/(26895): Unable to open '/system/framework/com.qti.location.sdk.jar': No such file or directory 
04-17 16:15:04.455: W/art(26895): Failed to open zip archive '/system/framework/com.qti.location.sdk.jar': I/O Error 
04-17 16:15:04.465: I/art(26895): Rejecting re-init on previously-failed class java.lang.Class<javax.activation.DataHandler> 
04-17 16:15:04.465: I/art(26895): Rejecting re-init on previously-failed class java.lang.Class<javax.activation.DataHandler> 
04-17 16:15:04.465: I/art(26895): Rejecting re-init on previously-failed class java.lang.Class<javax.activation.DataHandler> 
04-17 16:15:04.465: I/art(26895): Rejecting re-init on previously-failed class java.lang.Class<javax.activation.DataHandler> 
04-17 16:15:04.465: I/art(26895): Rejecting re-init on previously-failed class java.lang.Class<javax.activation.DataHandler> 
04-17 16:15:04.465: I/art(26895): Rejecting re-init on previously-failed class java.lang.Class<javax.activation.DataHandler> 
04-17 16:15:04.465: I/art(26895): Rejecting re-init on previously-failed class java.lang.Class<javax.activation.DataHandler> 
04-17 16:15:04.465: I/art(26895): Rejecting re-init on previously-failed class java.lang.Class<javax.activation.DataHandler> 
04-17 16:15:04.475: I/art(26895): Rejecting re-init on previously-failed class java.lang.Class<javax.activation.DataHandler> 
04-17 16:15:04.475: I/art(26895): Rejecting re-init on previously-failed class java.lang.Class<javax.activation.DataHandler> 
04-17 16:15:04.475: I/art(26895): Rejecting re-init on previously-failed class java.lang.Class<javax.activation.DataHandler> 
04-17 16:15:04.475: I/art(26895): Rejecting re-init on previously-failed class java.lang.Class<javax.activation.DataHandler> 
04-17 16:15:04.475: I/art(26895): Rejecting re-init on previously-failed class java.lang.Class<javax.activation.DataHandler> 
04-17 16:15:04.485: I/art(26895): Rejecting re-init on previously-failed class java.lang.Class<javax.activation.DataHandler> 
04-17 16:15:04.485: E/AndroidRuntime(26895): FATAL EXCEPTION: Thread-6719 
04-17 16:15:04.485: E/AndroidRuntime(26895): Process: com.example.proactiveregistrationapplication, PID: 26895 
04-17 16:15:04.485: E/AndroidRuntime(26895): java.lang.NoClassDefFoundError: javax.activation.DataHandler 
04-17 16:15:04.485: E/AndroidRuntime(26895): at com.example.proactiveregistrationapplication.GMailSender.sendMail(GMailSender.java:52) 
04-17 16:15:04.485: E/AndroidRuntime(26895): at com.example.proactiveregistrationapplication.UnsubscribeActivity.SendPasswordRequestEmail(UnsubscribeActivity.java:216) 
04-17 16:15:04.485: E/AndroidRuntime(26895): at com.example.proactiveregistrationapplication.UnsubscribeActivity$3$1$1.run(UnsubscribeActivity.java:83) 
04-17 16:15:04.485: E/AndroidRuntime(26895): at java.lang.Thread.run(Thread.java:818) 
04-17 16:15:04.635: D/ViewRootImpl(26895): MSG_RESIZED_REPORT: ci=Rect(0, 72 - 0, 0) vi=Rect(0, 72 - 0, 759) or=1 
04-17 16:15:04.655: I/Timeline(26895): Timeline: Activity_idle id: [email protected] time:49039028 
04-17 16:15:04.945: D/ViewRootImpl(26895): #3 mView = null 
04-17 16:15:04.965: E/WindowManager(26895): android.view.WindowLeaked: Activity com.example.proactiveregistrationapplication.UnsubscribeActivity has leaked window com.android.internal.policy.PhoneWindow$DecorView{4f688cf V.E...... R......D 0,0-1002,565} that was originally added here 
04-17 16:15:04.965: E/WindowManager(26895):  at android.view.ViewRootImpl.<init>(ViewRootImpl.java:565) 
04-17 16:15:04.965: E/WindowManager(26895):  at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:326) 
04-17 16:15:04.965: E/WindowManager(26895):  at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91) 
04-17 16:15:04.965: E/WindowManager(26895):  at android.app.Dialog.show(Dialog.java:350) 
04-17 16:15:04.965: E/WindowManager(26895):  at com.example.proactiveregistrationapplication.UnsubscribeActivity$3.onClick(UnsubscribeActivity.java:99) 
04-17 16:15:04.965: E/WindowManager(26895):  at android.view.View.performClick(View.java:5697) 
04-17 16:15:04.965: E/WindowManager(26895):  at android.widget.TextView.performClick(TextView.java:10826) 
04-17 16:15:04.965: E/WindowManager(26895):  at android.view.View$PerformClick.run(View.java:22526) 
04-17 16:15:04.965: E/WindowManager(26895):  at android.os.Handler.handleCallback(Handler.java:739) 
04-17 16:15:04.965: E/WindowManager(26895):  at android.os.Handler.dispatchMessage(Handler.java:95) 
04-17 16:15:04.965: E/WindowManager(26895):  at android.os.Looper.loop(Looper.java:158) 
04-17 16:15:04.965: E/WindowManager(26895):  at android.app.ActivityThread.main(ActivityThread.java:7224) 
04-17 16:15:04.965: E/WindowManager(26895):  at java.lang.reflect.Method.invoke(Native Method) 
04-17 16:15:04.965: E/WindowManager(26895):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) 
04-17 16:15:04.965: E/WindowManager(26895):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 

답변

0

원인 : 정확한 원인은 나에게 알 수 없습니다. 나는 그것이 프로젝트 -> (오른쪽 클릭) -> Run as-> Run Configurations에서 찾을 수있는 런타임 클래스 경로의 구성 오류 일 수 있다고 생각한다. https://stackoverflow.com/a/34419/3576562.

내가 노력

여분의 노력 : "실행 구성"창에서, 나는 "안드로이드 응용 프로그램"탭 Android 기기,> 프로젝트에서 프로젝트의 이름과 일치 내 프로젝트의 이름을 확인했다 : 탭. 참고 : 이것은 내 NoClassDefFoundError 오류를 수정하지 않았으며 처음에는 프로젝트에서 "실행 구성"창의 이름이 일치하지 않았습니다.

이에

대체 솔루션 "java.lang.NoClassDefFoundError가 : javax.activation.DataHandler의는"실행 시간 오류가 이었다 새로운 안드로이드 프로젝트를 만들고 원래의 소스 코드와 안드로이드 매니페스트를 포함하여 원래 프로젝트에서 모든 내용을 복사 .

나는 또한 대체 이메일 솔루션을 사용했습니다.