O funcionamento do botão está correto, ele executa todas as linhas anteriores. Porém, ao instanciar um objeto Email
exibe o erro.
public void send(View view) {
EditText text = (EditText) findViewById(R.id.editText);
Switch iluminacao = (Switch) findViewById(R.id.switch1);
Switch wifi = (Switch) findViewById(R.id.switch2);
RatingBar mBar = (RatingBar) findViewById(R.id.ratingBar);
System.out.println(text.getText().toString() + iluminacao.isChecked() + wifi.isChecked() + mBar.getNumStars());
Email email = new Email();
email.sendEmail(text.getText().toString(), iluminacao.isChecked(),
wifi.isChecked(), mBar.getNumStars());
}
Classe Email
:
package com.morais.daniela.conectasp;
import android.os.Build;
import org.apache.commons.mail.DefaultAuthenticator;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.SimpleEmail;
/**
* Created by daniela on 23/03/15.
*/
public class Email {
private SimpleEmail email = new SimpleEmail();
//FIXME
//Adicionar email correto para onde deverá ser enviado!
public Email() {
email.setSSLOnConnect(true);
email.setHostName("smtp.gmail.com");
email.setSslSmtpPort("465");
email.setAuthenticator(new DefaultAuthenticator("[email protected]", "senha"));
}
/**
* Recebe feedbacks enviados pelo usuario e encaminha por email
* @param comments
* @param getIluminacao
* @param getWifi
* @param getStars
*/
public void sendEmail(String comments, boolean getIluminacao, boolean getWifi, float getStars) {
String iluminacao = "Não.";
String wifi = "Não.";
if (getIluminacao == true) {
iluminacao = "Sim.";
}
if (getWifi == true) {
wifi = "Sim.";
}
try {
email.setFrom("[email protected]");
email.setDebug(true);
email.setSubject("Feedback - ConectaSP");
email.setMsg("Houve problemas com a iluminação? " + iluminacao + "\n\n" + "Houve problemas com o wifi? " + wifi + "\n\n" + "Avaliação geral " + getStars + "\n\n" + "Comentários:\n" + comments + "\n\n" + "Informações gerais do aparelho\n" + Build.DEVICE + "\t" + Build.HARDWARE + "\t" + Build.MODEL);
email.addTo("[email protected]");
email.send();
} catch (EmailException e) {
System.err.println("Erro ao enviar email.");
}
}
}
Erro
03-24 12:37:36.277 4037-4037/com.morais.daniela.conectasp E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3103)
at android.view.View.performClick(View.java:3574)
at android.view.View$PerformClick.run(View.java:14293)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4448)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3098)
at android.view.View.performClick(View.java:3574)
at android.view.View$PerformClick.run(View.java:14293)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4448)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.VerifyError: com/morais/daniela/conectasp/Email
at com.morais.daniela.conectasp.FeedbackActivity.send(FeedbackActivity.java:53)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3098)
at android.view.View.performClick(View.java:3574)
at android.view.View$PerformClick.run(View.java:14293)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4448)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
at dalvik.system.NativeStart.main(Native Method)
activation.jar
email.jar
do pacote Javax. Você os incluiu em seu projeto?