好,爲了長話短說,我有一個用戶註冊應用程序的對話框片段。他們輸入他們的電子郵件和密碼,並且應該向他們發送電子郵件,告訴應用程序歡迎。出於某種原因,我不斷收到此錯誤Android工作室Javamail API錯誤
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.sr116.art_buzz, PID: 5284
java.lang.NoClassDefFoundError: javax.activation.DataHandler
at javax.mail.internet.MimeMessage.setContent(MimeMessage.java:1516)
at javax.mail.internet.MimeBodyPart.setText(MimeBodyPart.java:1183)
at javax.mail.internet.MimeMessage.setText(MimeMessage.java:1555)
at javax.mail.internet.MimeMessage.setText(MimeMessage.java:1539)
at com.sr116.art_buzz.SignUpDialog$2.onClick(SignUpDialog.java:68)
at android.view.View.performClick(View.java:4633)
at android.view.View$PerformClick.run(View.java:19330)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
這裏是我的代碼:
public class SignUpDialog extends DialogFragment
{
private static final String TAG = "com.sr116.art_buzz";
//from and to
final String userName = "[email protected]";
final String password = "password";
//Recipients email
private EditText signUpEmail;
//Users Password
private EditText signUpPassword;
//signUpButton
Button signUpButton;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//In fragments must use view to access ids
View view = inflater.inflate(R.layout.sign_up_dialog, null);
signUpEmail = (EditText) view.findViewById(R.id.signUpEmail);
signUpPassword =(EditText) view.findViewById(R.id.signUpPassword);
signUpButton = (Button) view.findViewById(R.id.signUpButton);
Properties props = new Properties();
props.put("mail.smtp.starttls.enable","true");
props.put("mail.smtp.auth","true");
props.put("mail.smtp.host","smtp.gmail.com");
props.put("mail.smtp.port","587");
final Session session= Session.getInstance(props,
new javax.mail.Authenticator(){
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication(userName,password);
}
});
signUpButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v) {
try{
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("[email protected]"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(signUpEmail.getText().toString()));
message.setSubject("Testing");
message.setText("Still testing!!!");
Transport.send(message);
}catch (Exception e)
{
throw new RuntimeException(e);
}
}
});
return view;
}
}
搖籃:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.sr116.art_buzz"
minSdkVersion 19
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
android {
packagingOptions {
pickFirst 'META-INF/LICENSE.txt' // picks the JavaMail license file
}
}
repositories {
jcenter()
maven {
url "https://maven.java.net/content/groups/public/"
}
}
dependencies {
compile 'javax.mail:mail:1.5.0-b01'
compile 'javax.activation:activation:1.1.1'
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.1.0'
testCompile 'junit:junit:4.12'
compile files('libs/javax.mail.jar')
compile files('libs/activation-1.1.1.jar')
}
當我做他們說的,我得到這個錯誤錯誤:執行失敗的任務':app:compileDebugJavaWithJavac'。 > java.io.FileNotFoundException:C:\ Users \ SR116 \ AndroidStudioProjects \ Art_Buzz \ app \ libs \ activation-1.1.1.jar(系統找不到指定的文件) – user2626734
您的gradle構建文件中包含了什麼內容?不應該提及activation-1.1.1.jar。 –
我用我的gradle構建文件更新了我的帖子 – user2626734